forked from zaclys/searxng
[fix] pep8
This commit is contained in:
parent
d959cb1c05
commit
611f4e2a86
|
@ -1,4 +1,4 @@
|
|||
## Google (Web)
|
||||
# Google (Web)
|
||||
#
|
||||
# @website https://www.google.com
|
||||
# @provide-api yes (https://developers.google.com/custom-search/)
|
||||
|
@ -9,7 +9,7 @@
|
|||
# @parse url, title, content, suggestion
|
||||
|
||||
from urllib import urlencode
|
||||
from urlparse import unquote,urlparse,parse_qsl
|
||||
from urlparse import urlparse, parse_qsl
|
||||
from lxml import html
|
||||
from searx.engines.xpath import extract_text, extract_url
|
||||
|
||||
|
@ -23,7 +23,10 @@ google_hostname = 'www.google.com'
|
|||
search_path = '/search'
|
||||
redirect_path = '/url'
|
||||
images_path = '/images'
|
||||
search_url = 'https://' + google_hostname + search_path + '?{query}&start={offset}&gbv=1'
|
||||
search_url = ('https://' +
|
||||
google_hostname +
|
||||
search_path +
|
||||
'?{query}&start={offset}&gbv=1')
|
||||
|
||||
# specific xpath variables
|
||||
results_xpath = '//li[@class="g"]'
|
||||
|
@ -36,15 +39,18 @@ images_xpath = './/div/a'
|
|||
image_url_xpath = './@href'
|
||||
image_img_src_xpath = './img/@src'
|
||||
|
||||
|
||||
# remove google-specific tracking-url
|
||||
def parse_url(url_string):
|
||||
parsed_url = urlparse(url_string)
|
||||
if parsed_url.netloc in [google_hostname, ''] and parsed_url.path==redirect_path:
|
||||
if (parsed_url.netloc in [google_hostname, '']
|
||||
and parsed_url.path == redirect_path):
|
||||
query = dict(parse_qsl(parsed_url.query))
|
||||
return query['q']
|
||||
else:
|
||||
return url_string
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10
|
||||
|
@ -74,11 +80,13 @@ def response(resp):
|
|||
try:
|
||||
url = parse_url(extract_url(result.xpath(url_xpath), search_url))
|
||||
parsed_url = urlparse(url)
|
||||
if parsed_url.netloc==google_hostname and parsed_url.path==search_path:
|
||||
if (parsed_url.netloc == google_hostname
|
||||
and parsed_url.path == search_path):
|
||||
# remove the link to google news
|
||||
continue
|
||||
|
||||
if parsed_url.netloc==google_hostname and parsed_url.path==images_path:
|
||||
if (parsed_url.netloc == google_hostname
|
||||
and parsed_url.path == images_path):
|
||||
# images result
|
||||
results = results + parse_images(result)
|
||||
else:
|
||||
|
@ -99,6 +107,7 @@ def response(resp):
|
|||
# return results
|
||||
return results
|
||||
|
||||
|
||||
def parse_images(result):
|
||||
results = []
|
||||
for image in result.xpath(images_xpath):
|
||||
|
|
Loading…
Reference in New Issue