YTcrawl.py 476 B

1234567891011121314151617
  1. import csv
  2. from youtube_search import YoutubeSearch
  3. results = YoutubeSearch('微電影', max_results=100).to_dict()
  4. print(results[0].keys())
  5. print(len(results))
  6. with open('youtubeReport.csv', 'w', newline='',encoding='UTF-8') as csvfile:
  7. writer = csv.writer(csvfile)
  8. writer.writerow(['channel', 'title', 'views'])
  9. for r in results:
  10. print([r['channel'], r['title'], r['views']])
  11. writer.writerow([r['channel'], r['title'], r['views']])