add duckduckgo search
This commit is contained in:
parent
0b3cfe6c8d
commit
2892f3d12e
1 changed files with 21 additions and 0 deletions
21
ox/web/duckduckgo.py
Normal file
21
ox/web/duckduckgo.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import re
|
||||
import urllib
|
||||
import ox
|
||||
from ox import stripTags, decodeHtml
|
||||
from ox.utils import json
|
||||
from ox.cache import readUrl
|
||||
|
||||
|
||||
def find(query, timeout=ox.cache.cache_timeout):
|
||||
params = urllib.urlencode({'q': query})
|
||||
url = 'http://duckduckgo.com/html/?' + params
|
||||
print url
|
||||
data = readUrl(url, timeout=timeout)
|
||||
results = []
|
||||
regex = '<a .*?class="l le" href="(.+?)">(.*?)</a>.*?<div class="cra">(.*?)</div>'
|
||||
for r in re.compile(regex, re.DOTALL).findall(data):
|
||||
results.append((stripTags(decodeHtml(r[1])), r[0], stripTags(decodeHtml(r[2]))))
|
||||
return results
|
||||
|
Loading…
Reference in a new issue