Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
from celeryapp import app


USER_AGENT = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'


@app.task
def song_links():
page = requests.get(
'http://www.songlyrics.com/taylor-swift-lyrics/',
headers={'user-agent': USER_AGENT})
page = requests.get('http://www.songlyrics.com/taylor-swift-lyrics/')
parsed_content = BeautifulSoup(page.content, 'html.parser')
links = parsed_content.find('div', {'id': 'colone-container'})
links = links.find('table', {'class': 'tracklist'})
Expand All @@ -33,8 +28,7 @@ def song_links():

@app.task
def song_lyrics(url, title):
page = requests.get(url, headers={'user-agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'})
# have to mimic google bot here
page = requests.get(url)
parsed_content = BeautifulSoup(page.content, 'html.parser')
lyrics = parsed_content.find('p', {'id':'songLyricsDiv'}).text
filename = os.path.join(OUTPUT_DIR, '{}.txt'.format(title))
Expand Down