2024年12月

import sys
import datetime
import os

def print_with_lineno(message):
    frame = sys._getframe(1)  # 获取调用者的帧
    lineno = frame.f_lineno  # 行号
    filename = os.path.basename(frame.f_code.co_filename)  # 提取文件名
    current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # 格式化时间
    print(f"{current_time} - {filename} - Line {lineno}: {message}")

# 示例
print_with_lineno("This is a test message")
print_with_lineno("Another message")

url = f'https://www.google.com/'
# 创建一个会话对象
session = requests.Session()

# 设置代理
proxies = {
    "http": "http://127.0.0.1:1080",
    "https": "http://127.0.0.1:1080",
}
session.proxies.update(proxies)

response = session.get(f'{url}{page}')
print(response.text)
with open(f'pages/{page}.html', 'w') as f:
    f.write(response.text)
page_lis = tree.xpath('//ol[@class="pagination-parts"]/li/a')
page_total = int(page_lis[-1].text)