12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- from lxml import html
- from cgi import escape
- import re
- categories = ['general']
- language_support = True
- base_url = 'https://startpage.com/'
- search_url = base_url + 'do/search'
- results_xpath = '//div[@class="result"]'
- link_xpath = './/h3/a'
- def request(query, params):
- offset = (params['pageno'] - 1) * 10
- params['url'] = search_url
- params['method'] = 'POST'
- params['data'] = {'query': query,
- 'startat': offset}
-
- if params['language'] != 'all':
- params['data']['with_language'] = ('lang_' +
- params['language'].split('_')[0])
- return params
- def response(resp):
- results = []
- dom = html.fromstring(resp.content)
-
- for result in dom.xpath(results_xpath):
- links = result.xpath(link_xpath)
- if not links:
- continue
- link = links[0]
- url = link.attrib.get('href')
- try:
- title = escape(link.text_content())
- except UnicodeDecodeError:
- continue
-
- if re.match("^http(s|)://www.google.[a-z]+/aclk.*$", url):
- continue
- if result.xpath('./p[@class="desc"]'):
- content = escape(result.xpath('./p[@class="desc"]')[0]
- .text_content())
- else:
- content = ''
-
- results.append({'url': url,
- 'title': title,
- 'content': content})
-
- return results
|