fix: 修复科技日报偶尔出现日期匹配失败问题
This commit is contained in:
parent
e134004f2d
commit
5950005bac
@ -68,6 +68,7 @@ async def getData(start_date: datetime, end_date: datetime):
|
||||
months = []
|
||||
# 从开始日期到结束日期,每个月份都添加到列表中
|
||||
current_date = start_date
|
||||
current_date = current_date.replace(day=1)
|
||||
while current_date <= end_date:
|
||||
months.append(current_date)
|
||||
# 增加一个月
|
||||
@ -80,7 +81,8 @@ async def getData(start_date: datetime, end_date: datetime):
|
||||
# 构造URL
|
||||
url = f'https://digitalpaper.stdaily.com/http_www.kjrb.com/kjrb/html/{month.strftime("%Y-%m")}/period.xml'
|
||||
"""https://digitalpaper.stdaily.com/http_www.kjrb.com/kjrb/html/2011-10/period.xml"""
|
||||
print(url)
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), url)
|
||||
try:
|
||||
async with AsyncClient(headers=headers, timeout=60) as client:
|
||||
response = await client.get(url)
|
||||
response.encoding = response.charset_encoding
|
||||
@ -90,10 +92,9 @@ async def getData(start_date: datetime, end_date: datetime):
|
||||
for period in soup.select("period"):
|
||||
period_name = datetime.strptime(period.select_one("period_name").text.strip(), "%Y-%m-%d")
|
||||
front_page = period.select_one("front_page").text.strip()
|
||||
try:
|
||||
url1 = f"https://digitalpaper.stdaily.com/http_www.kjrb.com/kjrb/html/{period_name.strftime('%Y-%m/%d')}/{front_page}"
|
||||
"""https://digitalpaper.stdaily.com/http_www.kjrb.com/kjrb/html/2024-10/30/node_2.htm"""
|
||||
print(url1)
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), url1)
|
||||
response2 = await client.get(url1)
|
||||
response2.encoding = response2.charset_encoding
|
||||
print(f"二级连接状态:{response2.status_code}")
|
||||
@ -104,7 +105,7 @@ async def getData(start_date: datetime, end_date: datetime):
|
||||
banmianhao = item.text.split(":")[0]
|
||||
url2 = f"https://digitalpaper.stdaily.com/http_www.kjrb.com/kjrb/html/{period_name.strftime('%Y-%m/%d')}/" + item.get(
|
||||
"href").replace("./", "").strip()
|
||||
print(url2)
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), url2)
|
||||
response3 = await client.get(url2)
|
||||
response3.encoding = response3.charset_encoding
|
||||
print(f"三级连接状态:{response3.status_code}")
|
||||
@ -129,7 +130,7 @@ async def getData(start_date: datetime, end_date: datetime):
|
||||
if await collection.find_one({"detail_url": url3}, {"_id": False}):
|
||||
continue
|
||||
title = item2.text.strip()
|
||||
print(url3)
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), url3)
|
||||
response4 = await client.get(url3)
|
||||
response4.encoding = response4.charset_encoding
|
||||
print(f"四级连接状态:{response4.status_code}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user