根据 zltzlt 大佬的代码改编
[code]# -*- coding: utf-8 -*-
from requests import get
from re import findall
import easygui as eg
from time import sleep
res = get("https://fishc.com.cn/bestanswer.php?mod=huzhu&type=undo").text # 下载网页
last = int(findall(r'<span title="共 (\d+?) 页"> / \1 页</span>', res)[0]) # 获取最后一页
# 注:\1 用于引用前面编号为 1 的子组
fir_n = ''
while 1:
i=1
# 下载对应页数的网页,在网页后面加上 page 参数即可
res = get(f"https://fishc.com.cn/bestanswer.php?mod=huzhu&type=undo&page={i}").text
# 获取所有问题帖的名字
name = findall(r'<a href="https://fishc.com.cn/thread-\d+?-1-1.html" target="_blank">(.+?)</a>', res)
# 获取回答数
ans = findall(r'<font color="#999999">(\d+?)</font>', res)
# 获取时间
time = findall(r'<font color="#999999">(\d+?-\d+?-\d+? \d+?:\d+?)</font>', res)
if name[0] != fir_n:
print("\r☆ 检查到新的问题贴了!!! ", end="")
fir_n = name[0]
mmm = '标题:' + fir_n + '\n回答数:' + ans[0] + '\ntime:' + time[0]
eg.msgbox(mmm)
else:
print("\r没有检查到新的问题贴 ", end="")
# time.sleep(5)
# for j, a, t in zip(name, ans, time):
# print("标题:" + j, "回答数:" + a, "提问时间:" + t, sep="\n", end="\n\n") # 打印相应的内容
sleep(3)[/code]