123456789101112131415161718192021222324252627282930 |
- """
- @author: luojunhui
- """
- import json
- from spider.toutiao import parse_detail, search_article
- with open("test_return.json", encoding="utf-8") as f:
- video_data = json.loads(f.read())
- L = []
- for video_obj in video_data['data']:
- title = video_obj['title']
- print(title)
- urls = search_article(title)
- if urls:
- search_list = []
- for url in urls:
- try:
- res_o = parse_detail(url)
- search_list.append(res_o)
- except Exception as e:
- print(e)
- video_obj['search_list'] = search_list
- L.append(video_obj)
- else:
- continue
- with open("search_tt.json", "w", encoding="utf-8") as f:
- f.write(json.dumps(L, ensure_ascii=False, indent=4))
|