<jupyter_start><jupyter_text>Webscraping 40k Hindi songs We'll be scraping http://giitaayan.com/  Phase 2 In Phase 2, we will scrape the song lyrics from all the song pages<jupyter_code>from selenium import webdriver
import pandas as pd
import csv
import time
Chrome = webdriver.Chrome
chromedriver = './chromedriver'
browser = Chrome(chromedriver)
# Table headers for the csv file
table_headers = ['Song', 'Film', 'Year' 'Music Director', 'Lyricist', 'Singers']
# Opening the file in write mode and hence creating a new file with just the headers
with open(r'hindi_lyrics_phase2.csv', 'w') as file:
    writer = csv.writer(file)
    writer.writerow(table_headers)
# Reading the data which was scraped in Phase 1
df = pd.read_csv('hindi_lyrics_phase1.csv')
df.head()
%%time

# This for loop iterates over each row of the csv file
for i in range (len(df)):
    # Reading each song row as a list
    song_row = list(df.iloc[i])
    
    # Extracting the song page url from each row
    song_url = song_row[0]

    time.sleep(1)
    
    try:
        # Opening the song page in the browser
        browser.get(song_url)
        
        # The given button needs to be clicked to transliterate from English Script to Hindi
        browser.find_element_by_id('langName').click()
        
        # Replacing the first item of the row (song url) with the lyrics of the songs
        song_row[0] = browser.find_element_by_id('ConvertedText').text
        
        # Writing each row to the csv file
        # Notice that the file is opened in append mode
        with open(r'hindi_lyrics_phase2.csv', 'a') as file:
            writer = csv.writer(file)
            writer.writerow(song_row)
        
        # Printing progress
        print(f'Writing {i+1} of {len(df)}')
    except Exception as e:
        print(e)
        
pbar.close()<jupyter_output>Writing 1 of 10056
Writing 2 of 10056
Writing 3 of 10056
Writing 4 of 10056
Writing 5 of 10056
Writing 6 of 10056
Writing 7 of 10056
Writing 8 of 10056
Writing 9 of 10056
Writing 10 of 10056
Writing 11 of 10056
Writing 12 of 10056
Writing 13 of 10056
Writing 14 of 10056
Writing 15 of 10056
Writing 16 of 10056
Writing 17 of 10056
Writing 18 of 10056
Writing 19 of 10056
Writing 20 of 10056
Writing 21 of 10056
Writing 22 of 10056
Writing 23 of 10056
Writing 24 of 10056
Writing 25 of 10056
Writing 26 of 10056
Writing 27 of 10056
Writing 28 of 10056
Writing 29 of 10056
Writing 30 of 10056
Writing 31 of 10056
Writing 32 of 10056
Writing 33 of 10056
Writing 34 of 10056
Writing 35 of 10056
Writing 36 of 10056
Writing 37 of 10056
Writing 38 of 10056
Writing 39 of 10056
Writing 40 of 10056
Writing 41 of 10056
Writing 42 of 10056
Writing 43 of 10056
Writing 44 of 10056
Writing 45 of 10056
Writing 46 of 10056
Writing 47 of 10056
Writing 48 of 10056
Writing 49 of 10056
Writing 50 of 10056
Writing 5[...]