We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 6f083c05 authored by jarkko's avatar jarkko

Fixed a bug that prevented scraping single pages.

parent daa9749f
......@@ -32,13 +32,15 @@ def parse_track(row):
return (None, None, None)
def fetch_tracks(user, request_delay=0.5):
num_pages = 1
url = 'http://last.fm/user/%s/library/recent' % user
soup = BeautifulSoup(urllib2.urlopen(url))
num_pages = int(soup.find('a', 'lastpage').contents[0]) + 1
try:
num_pages = int(soup.find('a', 'lastpage').contents[0])
except:
num_pages = 1
all_data = []
for cur_page in range(1, num_pages):
for cur_page in range(1, num_pages + 1):
data = parse_page(url + '?page=' + str(cur_page))
all_data += data
if cur_page < num_pages:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment