mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 05:03:07 +01:00
parent
be3112197b
commit
9298b71732
37
plugin.py
37
plugin.py
@ -71,35 +71,22 @@ class DDG(callbacks.Plugin):
|
|||||||
data = re.sub('\t|\r|\n', '', data)
|
data = re.sub('\t|\r|\n', '', data)
|
||||||
data = re.sub('\s{2,}', ' ', data)
|
data = re.sub('\s{2,}', ' ', data)
|
||||||
soup = BeautifulSoup(data)
|
soup = BeautifulSoup(data)
|
||||||
# DuckDuckGo lite uses tables for everything. Each WEB result is made
|
tds = soup.find_all('td')
|
||||||
# up of 3 <tr> tags:
|
for t in tds:
|
||||||
tables = soup.find_all('table')
|
if "1." in t.text:
|
||||||
|
res = t.next_sibling.next_sibling
|
||||||
# Sometimes there is an extra table for page navigation
|
break
|
||||||
try:
|
try:
|
||||||
webresults = tables[2].find_all('tr')
|
# 1) Fetch the result link.
|
||||||
except IndexError:
|
link = res.a.get('href')
|
||||||
webresults = tables[1].find_all('tr')
|
# 2) Get a result snippet.
|
||||||
if webresults:
|
snippet = res.parent.next_sibling.next_sibling.find("td",
|
||||||
try:
|
class_="result-snippet")
|
||||||
while 'result-sponsored' in webresults[0]["class"]:
|
snippet = snippet.text.strip()
|
||||||
self.log.debug("DDG: stripping 1 sponsored/ad result.")
|
|
||||||
webresults = webresults[4:]
|
|
||||||
except KeyError: pass
|
|
||||||
# 1) The link and title.
|
|
||||||
link = webresults[0].find('a').get('href')
|
|
||||||
# 2) A result snippet.
|
|
||||||
snippet = webresults[1].find("td", class_="result-snippet")
|
|
||||||
try:
|
|
||||||
snippet = snippet.text.strip()
|
|
||||||
except AttributeError:
|
|
||||||
snippet = webresults[1].td.text.strip()
|
|
||||||
# 3) The link-text; essentially the same as the link in 1), but with the
|
|
||||||
# URI (http(s)://) removed. We do not need this section.
|
|
||||||
|
|
||||||
s = format("%s - %u", snippet, link)
|
s = format("%s - %u", snippet, link)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
except AttributeError:
|
||||||
irc.error("No results found.")
|
irc.error("No results found.")
|
||||||
search = wrap(search, ['text'])
|
search = wrap(search, ['text'])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user