do not fail if no edit link on wikipedia
This commit is contained in:
parent
63cf69d05f
commit
9616b3477e
1 changed files with 9 additions and 7 deletions
|
@ -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 ''
|
||||
|
|
Loading…
Reference in a new issue