Merge pull request #1 from flow2000/v2

优化每日60秒新闻获取逻辑
This commit is contained in:
心流 2023-01-04 13:39:57 +08:00 committed by GitHub
commit 2a4200f659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,19 +23,18 @@ def get_topic(offset=0):
day_news = soup.find_all('p')
for i in range(len(day_news)):
text=day_news[i].get_text()
if i == 0:
continue
if i == 1:
res['time']=text
continue
if i == 2:
res['topic']=text
continue
if i == len(day_news)-1:
res['weiyu']=text
continue
new_list.append(text)
res['news']=new_list
if text!="":
new_list.append(text)
if len(new_list)>2:
res['time']=new_list[0]
res['topic']=new_list[1]
res['weiyu']=new_list[len(new_list)-1]
res['news']=new_list[2:-1]
else:
res['time']=""
res['topic']=""
res['weiyu']=""
res['news']=[]
except Exception as e:
print(str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())),e)
return None