From 9616b3477ebfa5c79bf77ce2cfc31a989ebaf7e8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 16 Sep 2007 18:33:08 +0000 Subject: [PATCH] do not fail if no edit link on wikipedia --- scrapeit/wikipedia.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scrapeit/wikipedia.py b/scrapeit/wikipedia.py index fbd9704..ff3597a 100644 --- a/scrapeit/wikipedia.py +++ b/scrapeit/wikipedia.py @@ -26,11 +26,13 @@ def searchByImdb(imdb_id, title=None, director=None): data = read_url(url) soup = BeautifulSoup(data) edit_url = soup('a', dict(href=re.compile('action=edit'), - title=re.compile('You can edit this page.')))[0]['href'] - edit_url = "http://en.wikipedia.org%s" % edit_url.replace('&', '&') - data = read_url(edit_url) - w_imdb_id = data.find('imdb_id') - if w_imdb_id > 0: - if imdb_id in data[w_imdb_id:w_imdb_id+50]: - return url + title=re.compile('You can edit this page.'))) + if edit_url: + edit_url = edit_url[0]['href'] + edit_url = "http://en.wikipedia.org%s" % edit_url.replace('&', '&') + data = read_url(edit_url) + w_imdb_id = data.find('imdb_id') + if w_imdb_id > 0: + if imdb_id in data[w_imdb_id:w_imdb_id+50]: + return url return ''