This commit is contained in:
2025-02-05 11:12:20 +08:00
parent 6d1042c21d
commit cbdb36456b
4 changed files with 13 additions and 12 deletions

View File

@@ -79,7 +79,7 @@ class News(object):
return output
def get_baidu_news(self):
url = "https://orz.ai/dailynews/?platform=baidu"
url = "https://top.baidu.com/api/board?platform=wise&tab=realtime"
# 获取当前日期和英文星期名
now = datetime.now()
current_date = now.strftime("%Y年%m月%d")
@@ -97,10 +97,11 @@ class News(object):
if response.status_code == 200:
post = response.json()
str = post['data']
# 提取content列表
str = post['data']['cards'][0]['content']
# 遍历列表并格式化每个字典的title, url然后添加到output字符串中
for index, article in enumerate(str, start=1):
title = article['title']
title = article['word']
# url = article['url']
# 使用f-string格式化字符串并添加到output中
output += f"{index}. : {title}\n"
@@ -123,8 +124,8 @@ class News(object):
if __name__ == "__main__":
news = News()
# print(news.get_baidu_news())
# msg = "@水牛-分身 今日百度新闻"
# q = re.sub(r"@.*?[\u2005|\s]", "", msg).replace(" ", "")
# print(q)
print(news.get_eng_news('nbc'))
print(news.get_baidu_news())
# # msg = "@水牛-分身 今日百度新闻"
# # q = re.sub(r"@.*?[\u2005|\s]", "", msg).replace(" ", "")
# # print(q)
# print(news.get_eng_news('nbc'))