diff --git a/sixty_api/sixty_api.py b/sixty_api/sixty_api.py index aabe27e..78aa093 100644 --- a/sixty_api/sixty_api.py +++ b/sixty_api/sixty_api.py @@ -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