Skip to content

Commit

Permalink
DDG: better exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
James Lu committed Dec 19, 2014
1 parent f6ff29e commit d2f1f32
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DDG/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ def search(self, irc, msg, args, text):
self.log.info(url)
irc.error(str(e), Raise=True)
soup = BeautifulSoup(data)
res = ''
for t in soup.find_all('td'):
if "1." in t.text:
res = t.next_sibling.next_sibling
if not res:
continue
try:
# 1) Get a result snippet.
snippet = res.parent.next_sibling.next_sibling.find("td",
Expand All @@ -81,7 +84,7 @@ def search(self, irc, msg, args, text):
s = format("%s - %u", snippet, link)
irc.reply(s)
return
except (AttributeError, UnboundLocalError):
except AttributeError:
continue
else:
irc.error("No results found.")
Expand Down

0 comments on commit d2f1f32

Please sign in to comment.