优化每日60秒新闻获取逻辑

This commit is contained in:
flow2000 2023-01-04 13:39:20 +08:00
parent ffd020004f
commit 84eb494b87

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
if text!="":
new_list.append(text)
res['news']=new_list
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