DDG: better exception handling

From: d2f1f32896
This commit is contained in:
James Lu 2014-12-18 16:25:12 -08:00
parent 1a6e0127bd
commit d462b09dd7

View File

@ -67,9 +67,12 @@ class DDG(callbacks.Plugin):
self.log.info(url) self.log.info(url)
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
soup = BeautifulSoup(data) soup = BeautifulSoup(data)
res = ''
for t in soup.find_all('td'): for t in soup.find_all('td'):
if "1." in t.text: if "1." in t.text:
res = t.next_sibling.next_sibling res = t.next_sibling.next_sibling
if not res:
continue
try: try:
# 1) Get a result snippet. # 1) Get a result snippet.
snippet = res.parent.next_sibling.next_sibling.find("td", snippet = res.parent.next_sibling.next_sibling.find("td",
@ -81,7 +84,7 @@ class DDG(callbacks.Plugin):
s = format("%s - %u", snippet, link) s = format("%s - %u", snippet, link)
irc.reply(s) irc.reply(s)
return return
except (AttributeError, UnboundLocalError): except AttributeError:
continue continue
else: else:
irc.error("No results found.") irc.error("No results found.")