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
Post a Comment