优化每日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') day_news = soup.find_all('p')
for i in range(len(day_news)): for i in range(len(day_news)):
text=day_news[i].get_text() text=day_news[i].get_text()
if i == 0: if text!="":
continue new_list.append(text)
if i == 1: if len(new_list)>2:
res['time']=text res['time']=new_list[0]
continue res['topic']=new_list[1]
if i == 2: res['weiyu']=new_list[len(new_list)-1]
res['topic']=text res['news']=new_list[2:-1]
continue else:
if i == len(day_news)-1: res['time']=""
res['weiyu']=text res['topic']=""
continue res['weiyu']=""
new_list.append(text) res['news']=[]
res['news']=new_list
except Exception as e: except Exception as e:
print(str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())),e) print(str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())),e)
return None return None