|
|
发表于
2023-11-19 23:12:21
来自手机
|
显示全部楼层
| 阅读模式
来自 天津
本帖最后由 黄金 于 2023-11-19 23:20 编辑
- # MT124527
- """
- 使用方法:
- python 历史上的某天.py;#获取今天的历史
- python 历史上的某天.py {日};#获取本月某日的历史
- python 历史上的某天.py {月} {日};#获取某月某日的历史
- """
- def get_command_input():
- import sys
- command_input = list()
- for i in sys.argv:
- command_input.append(i)
- return command_input
- gci = get_command_input()
- from datetime import datetime
- if len(gci) == 3:
- date = gci[2]
- month = gci[1]
- else:
- month = datetime.now().strftime("%m")
- url = "https://baike.baidu.com/cms/home/eventsOnHistory/" + month + ".json"
- import httpx
- response = httpx.get(url, verify=False)
- response.raise_for_status() # 检查请求是否成功
- data = response.text
- import json
- data = json.loads(data)
- if "date" not in locals():
- if len(gci) == 2:
- date = gci[1]
- else:
- date = datetime.now().strftime("%d")
- data = data[month][month + date]
- from bs4 import BeautifulSoup
- print("历史上的" + month + "月" + date + "日")
- for i in data:
- i["title"] = BeautifulSoup(i["title"], "html.parser").get_text() # 去除html标签
- print(i["year"] + "\t" + i["title"])
复制代码
不要问我为什么不在原帖更新(多水一贴) |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|