forked from loldja/API-and-scraping-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_dylan.py
34 lines (28 loc) · 812 Bytes
/
scrape_dylan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
import requests
import re
import os
from time import sleep
artist_dict = {}
url = 'http://www.songlyrics.com/bob-dylan-lyrics/'
response = requests.get(url)
page = response.text
page = BeautifulSoup(page, 'lxml')
for j in page.find_all(href=re.compile("http://www.songlyrics.com/bob-dylan/.*lyrics")):
artist_dict[j.text] = j['href']
songs_list = []
lyrics_dict = {}
count = 1
for k,v in artist_dict.items():
url = "%s"%(v)
response = requests.get(url)
page = response.text
page = BeautifulSoup(page, 'lxml')
lyrics = page.find('p', id='songLyricsDiv')
lyrics_dict[k] = {v, lyrics}
sleep(0.03)
df = pd.DataFrame(lyrics_dict)
df.to_csv(r'~/Notebooks/lyrics_data2/%s.csv' % count)
count += 1