From 717644150a26c7eaf9c0e03d42a16b2dc6099a13 Mon Sep 17 00:00:00 2001 From: ShkSalmanAhmad Date: Thu, 24 Oct 2019 10:12:33 +0500 Subject: [PATCH] Create Youtube_Trends_DataCrawl.py This python code crawl data from a saved youtube trending videos page and then stores the title and links of those videos in a csv file. --- .../Youtube_Trends_DataCrawl.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Youtube Trends Crawler/Youtube_Trends_DataCrawl.py diff --git a/Youtube Trends Crawler/Youtube_Trends_DataCrawl.py b/Youtube Trends Crawler/Youtube_Trends_DataCrawl.py new file mode 100644 index 0000000..71e06d6 --- /dev/null +++ b/Youtube Trends Crawler/Youtube_Trends_DataCrawl.py @@ -0,0 +1,29 @@ +import csv +from bs4 import BeautifulSoup + +source = open('Trending - YouTube.html', encoding='utf-8') + + + +soup = BeautifulSoup(source, 'lxml') + +with open('trendingLinks.csv', 'w',newline='', encoding='utf-8') as csvwritefile: + + + + + csvwriter = csv.writer(csvwritefile) + + csvwriter.writerow(['titles', 'links']) + + for renderer in soup.find_all('a', 'yt-simple-endpoint style-scope ytd-video-renderer'): + titles= renderer['title'] + try: + links = renderer['href'] + except Exception as e: + href = None + print(e.__str__) + + csvwriter.writerow([titles,links]) +csvwritefile.close() +