forked from Archives/searxng
Merge pull request #88 from pointhi/engines
update and fix search enginesdependabot/pip/master/sphinx-6.1.3
commit
f36d1e28fa
@ -1,48 +1,81 @@
|
||||
## Bing (Web)
|
||||
#
|
||||
# @website https://www.bing.com
|
||||
# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
|
||||
#
|
||||
# @using-api no (because of query limit)
|
||||
# @results HTML (using search portal)
|
||||
# @stable no (HTML can change)
|
||||
# @parse url, title, content
|
||||
#
|
||||
# @todo publishedDate
|
||||
|
||||
from urllib import urlencode
|
||||
from cgi import escape
|
||||
from lxml import html
|
||||
|
||||
base_url = 'http://www.bing.com/'
|
||||
search_string = 'search?{query}&first={offset}'
|
||||
# engine dependent config
|
||||
categories = ['general']
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
# search-url
|
||||
base_url = 'https://www.bing.com/'
|
||||
search_string = 'search?{query}&first={offset}'
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10 + 1
|
||||
|
||||
if params['language'] == 'all':
|
||||
language = 'en-US'
|
||||
else:
|
||||
language = params['language'].replace('_', '-')
|
||||
|
||||
search_path = search_string.format(
|
||||
query=urlencode({'q': query, 'setmkt': language}),
|
||||
offset=offset)
|
||||
|
||||
params['cookies']['SRCHHPGUSR'] = \
|
||||
'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
|
||||
#if params['category'] == 'images':
|
||||
# params['url'] = base_url + 'images/' + search_path
|
||||
|
||||
params['url'] = base_url + search_path
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
dom = html.fromstring(resp.content)
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath('//div[@class="sa_cc"]'):
|
||||
link = result.xpath('.//h3/a')[0]
|
||||
url = link.attrib.get('href')
|
||||
title = ' '.join(link.xpath('.//text()'))
|
||||
content = escape(' '.join(result.xpath('.//p//text()')))
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'content': content})
|
||||
|
||||
# return results if something is found
|
||||
if results:
|
||||
return results
|
||||
|
||||
# parse results again if nothing is found yet
|
||||
for result in dom.xpath('//li[@class="b_algo"]'):
|
||||
link = result.xpath('.//h2/a')[0]
|
||||
url = link.attrib.get('href')
|
||||
title = ' '.join(link.xpath('.//text()'))
|
||||
content = escape(' '.join(result.xpath('.//p//text()')))
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'content': content})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -0,0 +1,81 @@
|
||||
## Bing (Images)
|
||||
#
|
||||
# @website https://www.bing.com/images
|
||||
# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
|
||||
#
|
||||
# @using-api no (because of query limit)
|
||||
# @results HTML (using search portal)
|
||||
# @stable no (HTML can change)
|
||||
# @parse url, title, img_src
|
||||
#
|
||||
# @todo currently there are up to 35 images receive per page, because bing does not parse count=10. limited response to 10 images
|
||||
|
||||
from urllib import urlencode
|
||||
from cgi import escape
|
||||
from lxml import html
|
||||
from yaml import load
|
||||
import re
|
||||
|
||||
# engine dependent config
|
||||
categories = ['images']
|
||||
paging = True
|
||||
|
||||
# search-url
|
||||
base_url = 'https://www.bing.com/'
|
||||
search_string = 'images/search?{query}&count=10&first={offset}'
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10 + 1
|
||||
|
||||
# required for cookie
|
||||
language = 'en-US'
|
||||
|
||||
search_path = search_string.format(
|
||||
query=urlencode({'q': query}),
|
||||
offset=offset)
|
||||
|
||||
params['cookies']['SRCHHPGUSR'] = \
|
||||
'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
|
||||
|
||||
params['url'] = base_url + search_path
|
||||
|
||||
print(params['url'])
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
dom = html.fromstring(resp.content)
|
||||
|
||||
# init regex for yaml-parsing
|
||||
p = re.compile( '({|,)([a-z]+):(")')
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath('//div[@class="dg_u"]'):
|
||||
link = result.xpath('./a')[0]
|
||||
|
||||
# parse yaml-data (it is required to add a space, to make it parsable)
|
||||
yaml_data = load(p.sub( r'\1\2: \3', link.attrib.get('m')))
|
||||
|
||||
title = link.attrib.get('t1')
|
||||
#url = 'http://' + link.attrib.get('t3')
|
||||
url = yaml_data.get('surl')
|
||||
img_src = yaml_data.get('imgurl')
|
||||
|
||||
# append result
|
||||
results.append({'template': 'images.html',
|
||||
'url': url,
|
||||
'title': title,
|
||||
'content': '',
|
||||
'img_src': img_src})
|
||||
|
||||
# TODO stop parsing if 10 images are found
|
||||
if len(results) >= 10:
|
||||
break
|
||||
|
||||
# return results
|
||||
return results
|
@ -1,50 +1,86 @@
|
||||
## Bing (News)
|
||||
#
|
||||
# @website https://www.bing.com/news
|
||||
# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
|
||||
#
|
||||
# @using-api no (because of query limit)
|
||||
# @results HTML (using search portal)
|
||||
# @stable no (HTML can change)
|
||||
# @parse url, title, content, publishedDate
|
||||
|
||||
from urllib import urlencode
|
||||
from cgi import escape
|
||||
from lxml import html
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil import parser
|
||||
import re
|
||||
|
||||
# engine dependent config
|
||||
categories = ['news']
|
||||
|
||||
base_url = 'http://www.bing.com/'
|
||||
search_string = 'news/search?{query}&first={offset}'
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
# search-url
|
||||
base_url = 'https://www.bing.com/'
|
||||
search_string = 'news/search?{query}&first={offset}'
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10 + 1
|
||||
|
||||
if params['language'] == 'all':
|
||||
language = 'en-US'
|
||||
else:
|
||||
language = params['language'].replace('_', '-')
|
||||
|
||||
search_path = search_string.format(
|
||||
query=urlencode({'q': query, 'setmkt': language}),
|
||||
offset=offset)
|
||||
|
||||
params['cookies']['SRCHHPGUSR'] = \
|
||||
'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
|
||||
#if params['category'] == 'images':
|
||||
# params['url'] = base_url + 'images/' + search_path
|
||||
|
||||
params['url'] = base_url + search_path
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
dom = html.fromstring(resp.content)
|
||||
for result in dom.xpath('//div[@class="sa_cc"]'):
|
||||
link = result.xpath('.//h3/a')[0]
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath('//div[@class="sn_r"]'):
|
||||
link = result.xpath('.//div[@class="newstitle"]/a')[0]
|
||||
url = link.attrib.get('href')
|
||||
title = ' '.join(link.xpath('.//text()'))
|
||||
content = escape(' '.join(result.xpath('.//p//text()')))
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
content = escape(' '.join(result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_snip"]//text()')))
|
||||
|
||||
# parse publishedDate
|
||||
publishedDate = escape(' '.join(result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_ST"]//span[@class="sn_tm"]//text()')))
|
||||
|
||||
if results:
|
||||
return results
|
||||
if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
|
||||
timeNumbers = re.findall(r'\d+', publishedDate)
|
||||
publishedDate = datetime.now()\
|
||||
- timedelta(minutes=int(timeNumbers[0]))
|
||||
elif re.match("^[0-9]+ hour(s|) ago$", publishedDate):
|
||||
timeNumbers = re.findall(r'\d+', publishedDate)
|
||||
publishedDate = datetime.now()\
|
||||
- timedelta(hours=int(timeNumbers[0]))
|
||||
elif re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", publishedDate):
|
||||
timeNumbers = re.findall(r'\d+', publishedDate)
|
||||
publishedDate = datetime.now()\
|
||||
- timedelta(hours=int(timeNumbers[0]))\
|
||||
- timedelta(minutes=int(timeNumbers[1]))
|
||||
else:
|
||||
publishedDate = parser.parse(publishedDate)
|
||||
|
||||
for result in dom.xpath('//li[@class="b_algo"]'):
|
||||
link = result.xpath('.//h2/a')[0]
|
||||
url = link.attrib.get('href')
|
||||
title = ' '.join(link.xpath('.//text()'))
|
||||
content = escape(' '.join(result.xpath('.//p//text()')))
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'publishedDate': publishedDate,
|
||||
'content': content})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -1,45 +1,61 @@
|
||||
## Dailymotion (Videos)
|
||||
#
|
||||
# @website https://www.dailymotion.com
|
||||
# @provide-api yes (http://www.dailymotion.com/developer)
|
||||
#
|
||||
# @using-api yes
|
||||
# @results JSON
|
||||
# @stable yes
|
||||
# @parse url, title, thumbnail
|
||||
#
|
||||
# @todo set content-parameter with correct data
|
||||
|
||||
from urllib import urlencode
|
||||
from json import loads
|
||||
from lxml import html
|
||||
|
||||
# engine dependent config
|
||||
categories = ['videos']
|
||||
locale = 'en_US'
|
||||
paging = True
|
||||
|
||||
# search-url
|
||||
# see http://www.dailymotion.com/doc/api/obj-video.html
|
||||
search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page={pageno}&{query}' # noqa
|
||||
|
||||
# TODO use video result template
|
||||
content_tpl = '<a href="{0}" title="{0}" ><img src="{1}" /></a><br />'
|
||||
|
||||
paging = True
|
||||
search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=5&page={pageno}&{query}' # noqa
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
params['url'] = search_url.format(
|
||||
query=urlencode({'search': query, 'localization': locale}),
|
||||
pageno=params['pageno'])
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
search_res = loads(resp.text)
|
||||
|
||||
# return empty array if there are no results
|
||||
if not 'list' in search_res:
|
||||
return results
|
||||
return []
|
||||
|
||||
# parse results
|
||||
for res in search_res['list']:
|
||||
title = res['title']
|
||||
url = res['url']
|
||||
if res['thumbnail_360_url']:
|
||||
content = content_tpl.format(url, res['thumbnail_360_url'])
|
||||
else:
|
||||
content = ''
|
||||
if res['description']:
|
||||
description = text_content_from_html(res['description'])
|
||||
content += description[:500]
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
return results
|
||||
#content = res['description']
|
||||
content = ''
|
||||
thumbnail = res['thumbnail_360_url']
|
||||
|
||||
results.append({'template': 'videos.html',
|
||||
'url': url,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'thumbnail': thumbnail})
|
||||
|
||||
def text_content_from_html(html_string):
|
||||
desc_html = html.fragment_fromstring(html_string, create_parent=True)
|
||||
return desc_html.text_content()
|
||||
# return results
|
||||
return results
|
||||
|
@ -1,37 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
## Google (Web)
|
||||
#
|
||||
# @website https://www.google.com
|
||||
# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
|
||||
#
|
||||
# @using-api yes
|
||||
# @results JSON
|
||||
# @stable yes (but deprecated)
|
||||
# @parse url, title, content
|
||||
|
||||
from urllib import urlencode
|
||||
from json import loads
|
||||
|
||||
# engine dependent config
|
||||
categories = ['general']
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
# search-url
|
||||
url = 'https://ajax.googleapis.com/'
|
||||
search_url = url + 'ajax/services/search/web?v=2.0&start={offset}&rsz=large&safe=off&filter=off&{query}&hl={language}' # noqa
|
||||
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 8
|
||||
|
||||
language = 'en-US'
|
||||
if params['language'] != 'all':
|
||||
language = params['language'].replace('_', '-')
|
||||
|
||||
params['url'] = search_url.format(offset=offset,
|
||||
query=urlencode({'q': query}),
|
||||
language=language)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
search_res = loads(resp.text)
|
||||
|
||||
# return empty array if there are no results
|
||||
if not search_res.get('responseData', {}).get('results'):
|
||||
return []
|
||||
|
||||
# parse results
|
||||
for result in search_res['responseData']['results']:
|
||||
# append result
|
||||
results.append({'url': result['unescapedUrl'],
|
||||
'title': result['titleNoFormatting'],
|
||||
'content': result['content']})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -1,37 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
## Google (Images)
|
||||
#
|
||||
# @website https://www.google.com
|
||||
# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
|
||||
#
|
||||
# @using-api yes
|
||||
# @results JSON
|
||||
# @stable yes (but deprecated)
|
||||
# @parse url, title, img_src
|
||||
|
||||
from urllib import urlencode
|
||||
from json import loads
|
||||
|
||||
# engine dependent config
|
||||
categories = ['images']
|
||||
paging = True
|
||||
|
||||
# search-url
|
||||
url = 'https://ajax.googleapis.com/'
|
||||
search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe=off&filter=off&{query}' # noqa
|
||||
|
||||
paging = True
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 8
|
||||
|
||||
params['url'] = search_url.format(query=urlencode({'q': query}),
|
||||
offset=offset)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
search_res = loads(resp.text)
|
||||
if not search_res.get('responseData'):
|
||||
return []
|
||||
if not search_res['responseData'].get('results'):
|
||||
|
||||
# return empty array if there are no results
|
||||
if not search_res.get('responseData', {}).get('results'):
|
||||
return []
|
||||
|
||||
# parse results
|
||||
for result in search_res['responseData']['results']:
|
||||
href = result['originalContextUrl']
|
||||
title = result['title']
|
||||
if not result['url']:
|
||||
continue
|
||||
|
||||
# append result
|
||||
results.append({'url': href,
|
||||
'title': title,
|
||||
'content': '',
|
||||
'img_src': result['url'],
|
||||
'template': 'images.html'})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -1,43 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
## Google (News)
|
||||
#
|
||||
# @website https://www.google.com
|
||||
# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
|
||||
#
|
||||
# @using-api yes
|
||||
# @results JSON
|
||||
# @stable yes (but deprecated)
|
||||
# @parse url, title, content, publishedDate
|
||||
|
||||
from urllib import urlencode
|
||||
from json import loads
|
||||
from dateutil import parser
|
||||
|
||||
# search-url
|
||||
categories = ['news']
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
# engine dependent config
|
||||
url = 'https://ajax.googleapis.com/'
|
||||
search_url = url + 'ajax/services/search/news?v=2.0&start={offset}&rsz=large&safe=off&filter=off&{query}&hl={language}' # noqa
|
||||
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 8
|
||||
|
||||
language = 'en-US'
|
||||
if params['language'] != 'all':
|
||||
language = params['language'].replace('_', '-')
|
||||
|
||||
params['url'] = search_url.format(offset=offset,
|
||||
query=urlencode({'q': query}),
|
||||
language=language)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
search_res = loads(resp.text)
|
||||
|
||||
# return empty array if there are no results
|
||||
if not search_res.get('responseData', {}).get('results'):
|
||||
return []
|
||||
|
||||
# parse results
|
||||
for result in search_res['responseData']['results']:
|
||||
|
||||
# Mon, 10 Mar 2014 16:26:15 -0700
|
||||
# parse publishedDate
|
||||
publishedDate = parser.parse(result['publishedDate'])
|
||||
|
||||
# append result
|
||||
results.append({'url': result['unescapedUrl'],
|
||||
'title': result['titleNoFormatting'],
|
||||
'publishedDate': publishedDate,
|
||||
'content': result['content']})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -1,64 +1,99 @@
|
||||
#!/usr/bin/env python
|
||||
## Yahoo (Web)
|
||||
#
|
||||
# @website https://search.yahoo.com/web
|
||||
# @provide-api yes (https://developer.yahoo.com/boss/search/), $0.80/1000 queries
|
||||
#
|
||||
# @using-api no (because pricing)
|
||||
# @results HTML (using search portal)
|
||||
# @stable no (HTML can change)
|
||||
# @parse url, title, content, suggestion
|
||||
|
||||
from urllib import urlencode
|
||||
from urlparse import unquote
|
||||
from lxml import html
|
||||
from searx.engines.xpath import extract_text, extract_url
|
||||
|
||||
# engine dependent config
|
||||
categories = ['general']
|
||||
search_url = 'http://search.yahoo.com/search?{query}&b={offset}'
|
||||
paging = True
|
||||
language_support = True
|
||||
|
||||
# search-url
|
||||
search_url = 'https://search.yahoo.com/search?{query}&b={offset}&fl=1&vl=lang_{lang}'
|
||||
|
||||
# specific xpath variables
|
||||
results_xpath = '//div[@class="res"]'
|
||||
url_xpath = './/h3/a/@href'
|
||||
title_xpath = './/h3/a'
|
||||
content_xpath = './/div[@class="abstr"]'
|
||||
suggestion_xpath = '//div[@id="satat"]//a'
|
||||
|
||||
paging = True
|
||||
|
||||
|
||||
# remove yahoo-specific tracking-url
|
||||
def parse_url(url_string):
|
||||
endings = ['/RS', '/RK']
|
||||
endpositions = []
|
||||
start = url_string.find('http', url_string.find('/RU=')+1)
|
||||
|
||||
for ending in endings:
|
||||
endpos = url_string.rfind(ending)
|
||||
if endpos > -1:
|
||||
endpositions.append(endpos)
|
||||
|
||||
end = min(endpositions)
|
||||
|
||||
return unquote(url_string[start:end])
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10 + 1
|
||||
|
||||
if params['language'] == 'all':
|
||||
language = 'en'
|
||||
else:
|
||||
language = params['language'].split('_')[0]
|
||||
|
||||
params['url'] = search_url.format(offset=offset,
|
||||
query=urlencode({'p': query}))
|
||||
query=urlencode({'p': query}),
|
||||
lang=language)
|
||||
|
||||
# TODO required?
|
||||
params['cookies']['sB'] = 'fl=1&vl=lang_{lang}&sh=1&rw=new&v=1'\
|
||||
.format(lang=language)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# get response from search-request
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
dom = html.fromstring(resp.text)
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath(results_xpath):
|
||||
try:
|
||||
url = parse_url(extract_url(result.xpath(url_xpath), search_url))
|
||||
title = extract_text(result.xpath(title_xpath)[0])
|
||||
except:
|
||||
continue
|
||||
|
||||
content = extract_text(result.xpath(content_xpath)[0])
|
||||
results.append({'url': url, 'title': title, 'content': content})
|
||||
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'content': content})
|
||||
|
||||
# if no suggestion found, return results
|
||||
if not suggestion_xpath:
|
||||
return results
|
||||
|
||||
# parse suggestion
|
||||
for suggestion in dom.xpath(suggestion_xpath):
|
||||
# append suggestion
|
||||
results.append({'suggestion': extract_text(suggestion)})
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
Loading…
Reference in New Issue