From f8d5afbb465dd63057e97fd5a7ed1158c16808dc Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 11 Dec 2014 07:47:58 -0800 Subject: [PATCH] DDG: strip ads better + skip zeroclick info From: https://github.com/jlu5/SupyPlugins/commit/625ef777cdc292ca7b8562e697c44b748a84edf8 --- plugin.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugin.py b/plugin.py index 1e70dea04..d44718294 100644 --- a/plugin.py +++ b/plugin.py @@ -56,7 +56,7 @@ except ImportError: class DDG(callbacks.Plugin): """Searches for results on DuckDuckGo.""" threaded = True - + def search(self, irc, msg, args, text): """ @@ -74,14 +74,15 @@ class DDG(callbacks.Plugin): # DuckDuckGo lite uses tables for everything. Each WEB result is made # up of 3 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.