mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-24 04:19:48 +01:00
fix:添加user-agent修复新闻403错误
This commit is contained in:
parent
63dfcde4c8
commit
d31761e78a
1 changed files with 4 additions and 2 deletions
|
|
@ -125,7 +125,8 @@ def fetch_news_from_api(conn, source="thepaper"):
|
|||
]["get_news_from_newsnow"].get("url"):
|
||||
api_url = conn.config["plugins"]["get_news_from_newsnow"]["url"] + source
|
||||
|
||||
response = requests.get(api_url, timeout=10)
|
||||
headers = {"User-Agent": "Mozilla/5.0"}
|
||||
response = requests.get(api_url, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
|
|
@ -144,7 +145,8 @@ def fetch_news_from_api(conn, source="thepaper"):
|
|||
def fetch_news_detail(url):
|
||||
"""获取新闻详情页内容并使用MarkItDown清理HTML"""
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
headers = {"User-Agent": "Mozilla/5.0"}
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
# 使用MarkItDown清理HTML内容
|
||||
|
|
|
|||
Loading…
Reference in a new issue