Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…
- Loading branch information
0 parents
commit 7fea3c4
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
# Ignore output of scraper | |||
data.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
This scraper collects the weekly playlist of the radio show "Radio Renner" of the radio station Bremen4. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
import scraperwiki | |||
import urllib | |||
from bs4 import BeautifulSoup | |||
|
|||
|
|||
url = 'http://www.radiobremen.de/bremenvier/musik/playlists/radiorenner104.html' | |||
# webseite oeffnen | |||
fh = urllib.urlopen(url) | |||
# webseite einlesen | |||
html = fh.read() | |||
soup = BeautifulSoup(html) | |||
|
|||
def scrape_playlist(): | |||
|
|||
tab = soup.select('.top44_table') | |||
if tab: | |||
tr = tab[0].find_all('tr') | |||
else: | |||
print "Tabelle nicht gefunden" | |||
return | |||
|
|||
if not tr: | |||
print "Tabellenzeilen nicht gefunden" | |||
return | |||
|
|||
headlines = soup.find_all('h2') | |||
if headlines: | |||
datum = headlines[0].text | |||
datum = datum.replace('Radio Renner mit Tim Renner vom ', '') | |||
|
|||
else: | |||
print "Datum nicht gefunden" | |||
return | |||
|
|||
for row in tr[1:]: | |||
|
|||
entry = {} | |||
entry['Datum'] = datum | |||
feld1 = row.find_next('td', 'top44_table_zelle') | |||
feld2 = feld1.find_next_sibling() | |||
if feld2: | |||
interpret = feld2.text | |||
entry['Interpret'] = interpret | |||
feld3 = feld2.find_next_sibling() | |||
if feld3: | |||
titel = feld3.text | |||
entry['Titel'] = titel | |||
entry['ID'] = interpret + " - " + titel | |||
|
|||
scraperwiki.sqlite.save(unique_keys=['ID'], data=entry, table_name="Playlist Radio Renner Bremen4") | |||
|
|||
else: | |||
print "Titel nicht gefunden" | |||
|
|||
## MAIN ## | |||
scrape_playlist() | |||
|
|||
|