python - Surprising Array index error -


i trying scrape through website, , getting error not able understand. says index out of bounds fro 11th line, i'm not sure why happen or how fix it. pls hlp.

from bs4 import beautifulsoup import urllib.request import re  site = urllib.request.urlopen('http://duckduckgo.com/html/?q=example') data = site.read()  parsed = beautifulsoup(data) topics = parsed.findall('div', {'id': 'zero_click_topics'})[0] results = topics.findall('div', {'class': re.compile('results_*')})  print(results[0].text) 

error:

traceback (most recent call last):   file "c:/users/james/documents/superman/suduk.py", line 11, in <module>     topics = parsed.findall('div', {'id': 'zero_click_topics'})[0] indexerror: list index out of range 

if findall doesn't find any, there won't first element index. why wouldn't find any, haven't provided enough information answer that.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -