Skip to content

Commit

Permalink
DDG: strip ads better + skip zeroclick info
Browse files Browse the repository at this point in the history
  • Loading branch information
GLolol authored and GLolol committed Dec 11, 2014
1 parent 3c6126f commit 625ef77
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions DDG/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
class DDG(callbacks.Plugin):
"""Searches for results on DuckDuckGo."""
threaded = True

def search(self, irc, msg, args, text):
"""<query>
Expand All @@ -74,14 +74,15 @@ def search(self, irc, msg, args, text):
# DuckDuckGo lite uses tables for everything. Each WEB result is made
# up of 3 <tr> tags:
tables = soup.find_all('table')

webresults = tables[1].find_all('tr')

# Sometimes there is an extra table for page navigation
webresults = tables[2].find_all('tr')
if not webresults:
# Sometimes there will be another table for page navigation.
webresults = tables[2].find_all('tr')
webresults = tables[1].find_all('tr')
if webresults:
try:
if 'result-sponsored' in webresults[0]["class"]:
while 'result-sponsored' in webresults[0]["class"]:
self.log.debug("DDG: stripping 1 sponsored/ad result.")
webresults = webresults[4:]
except KeyError: pass
# 1) The link and title.
Expand Down

0 comments on commit 625ef77

Please sign in to comment.