获取:吾爱破解>挣悬赏>下载转存>0回复问题链接
[Python] 纯文本查看 复制代码 from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.options import Options
from datetime import datetime
# 设置无头浏览器
options = Options()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("--disable-gpu")
# 创建Edge浏览器对象
driver = webdriver.Edge(options=options)
# 设置隐式等待(等待元素加载的最长时间)
driver.implicitly_wait(10)
# 打开网页
driver.get("https://www.52pojie.cn/forum.php?mod=forumdisplay&fid=8&filter=specialtype&specialtype=reward&typeid=145&rewardtype=1")
# driver.get('https://www.52pojie.cn/forum-8-1.html')
# 获取当前日期
current_date = datetime.now().date()
# 将日期格式化为字符串 "YYYY-M-D"
date_str = current_date.strftime("%Y-%m-%d").replace('-0', '-')
# 查找表格行
tbodys = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.XPATH, "//table[@ID='threadlisttableid']/tbody"))
)
for tbody in tbodys:
if tbodys.index(tbody) >= 2:
lj = tbody.find_element(By.XPATH, ".//tr/th/a[2]").get_attribute("href")
shijian = tbody.find_element(By.XPATH, ".//tr/td[2]/em/span").text.split(' ')[0]
xiazai = tbody.find_element(By.XPATH, ".//td[@class='num']/a").text
# 比较两个日期
if shijian == date_str and xiazai == '0':
print(lj)
# 关闭浏览器
driver.quit() |