本帖最后由 chh322 于 2024-5-7 09:15 编辑
每周开会,做PPT要知道今天是今年第几周,放青龙面板 每天推送给自己微信
[Python] 纯文本查看 复制代码 import requests
from bs4 import BeautifulSoup
import notify
url = "https://m.tthuangli.com/"
# 发送 HTTP GET 请求
response = requests.get(url)
# 检查请求是否成功
if response.status_code == 200:
# 使用 BeautifulSoup 解析 HTML 内容
soup = BeautifulSoup(response.content, "html.parser")
# 查找包含日期的<span>标签
date_span = soup.find("span", class_="nowday")
# 查找第17周的第三个<p>标签
second_color_paragraphs = soup.find_all("p", class_="second_color")
week_text = ""
if len(second_color_paragraphs) >= 3:
week_text = second_color_paragraphs[2].get_text(strip=True)
# 查找农历年份的<div>标签
nong_li_nian_div = soup.find("div", class_="nong_li_nian")
# 查找星期的<div>标签
zhong_week_div = soup.find("div", class_="zhong_week")
# 初始化变量
date_text = ""
nong_li_nian_text = ""
zhong_week_text = ""
# 提取日期信息
if date_span:
date_text = date_span.get_text(strip=True)
# 提取农历年份信息
if nong_li_nian_div:
nong_li_nian_text = nong_li_nian_div.get_text(strip=True)
# 提取星期信息
if zhong_week_div:
zhong_week_text = zhong_week_div.get_text(strip=True)
# 格式化输出合并的信息
combined_result = f"日期: {date_text} 周期: {week_text}\n农历: {nong_li_nian_text} 星期: {zhong_week_text}"
print("提取到的结果:", combined_result)
notify.send("今日第几周", combined_result)
else:
print("请求失败,状态码:", response.status_code)
notify.send("今日第几周", response.status_code)
|