scrape_songmeanings



In [1]:
import requests, lxml.html
import pandas as pd

In [2]:
response = requests.get("http://songmeanings.com/popular/lyrics/?chart=2016-04-19")
doc = lxml.html.fromstring(response.content)

rows = []
table = doc.cssselect("table[summary]")[0]
for item in table.cssselect("tbody > tr.item"):
    cells = item.getchildren()
    row = [cells[0].text_content().strip(), cells[1].text_content().strip(), cells[2].text_content().strip()]
    rows.append(row)
    
df = pd.DataFrame(rows, columns=['rank', 'title', 'margin'])
df.set_index('rank', drop=True, inplace=True)
df


Out[2]:
title margin
rank
1 Simon and Garfunkel – The Sound of Silence Lyrics
2 Twenty One Pilots – Car Radio Lyrics +1
3 Hozier – Take Me to Church Lyrics +1
4 Dub Trio – We're Not Alone Lyrics
5 Coldplay – The Scientist Lyrics +1
6 Songs: Ohia – Coxcomb Red Lyrics -4
7 The Killers – Mr. Brightside Lyrics
8 David Bowie – Life on Mars? Lyrics
9 Panic! at the Disco – This Is Gospel Lyrics +2
10 Jeff Buckley – Lilac Wine Lyrics -5
11 System of a Down – Chop Suey! Lyrics
12 Pink Floyd – Wish You Were Here Lyrics -3
13 Ed Sheeran – The A Team Lyrics +3
14 Bon Iver – Skinny Love Lyrics -4
15 Imagine Dragons – Demons Lyrics -2
16 Queen – Bohemian Rhapsody Lyrics +1
17 Hozier – Cherry Wine Lyrics +1
18 Imagine Dragons – Radioactive Lyrics +3
19 Led Zeppelin – Stairway to Heaven Lyrics -4
20 Coldplay – Fix You Lyrics
21 Nirvana – Smells Like Teen Spirit Lyrics -7
22 Guns N' Roses – November Rain Lyrics +2
23 Of Monsters And Men – Little Talks Lyrics +2
24 Cold War Kids – First Lyrics
25 Alt-J – Breezeblocks Lyrics -3