Exemplo n.º 1
0
    def test_request(self):
        google.supported_languages = ['en', 'fr', 'zh-CN', 'iw']
        google.language_aliases = {'he': 'iw'}

        query = 'test_query'
        dicto = defaultdict(dict)
        dicto['pageno'] = 1
        dicto['language'] = 'fr-FR'
        dicto['time_range'] = ''
        params = google.request(query, dicto)
        self.assertIn('url', params)
        self.assertIn(query, params['url'])
        self.assertIn('google.fr', params['url'])
        self.assertIn('fr', params['url'])
        self.assertIn('fr', params['headers']['Accept-Language'])

        dicto['language'] = 'en-US'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('en', params['url'])
        self.assertIn('en', params['headers']['Accept-Language'])

        dicto['language'] = 'zh'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('zh-CN', params['url'])
        self.assertIn('zh-CN', params['headers']['Accept-Language'])

        dicto['language'] = 'he'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('iw', params['url'])
        self.assertIn('iw', params['headers']['Accept-Language'])
Exemplo n.º 2
0
    def test_request(self):
        google.supported_languages = ['en', 'fr', 'zh-CN', 'iw']
        google.language_aliases = {'he': 'iw'}

        query = 'test_query'
        dicto = defaultdict(dict)
        dicto['pageno'] = 1
        dicto['language'] = 'fr-FR'
        dicto['time_range'] = ''
        params = google.request(query, dicto)
        self.assertIn('url', params)
        self.assertIn(query, params['url'])
        self.assertIn('google.fr', params['url'])
        self.assertIn('fr', params['url'])
        self.assertIn('fr', params['headers']['Accept-Language'])

        dicto['language'] = 'en-US'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('en', params['url'])
        self.assertIn('en', params['headers']['Accept-Language'])

        dicto['language'] = 'zh'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('zh-CN', params['url'])
        self.assertIn('zh-CN', params['headers']['Accept-Language'])

        dicto['language'] = 'he'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('iw', params['url'])
        self.assertIn('iw', params['headers']['Accept-Language'])
Exemplo n.º 3
0
    def test_request(self):
        query = 'test_query'
        dicto = defaultdict(dict)
        dicto['pageno'] = 1
        dicto['language'] = 'fr_FR'
        params = google.request(query, dicto)
        self.assertIn('url', params)
        self.assertIn(query, params['url'])
        self.assertIn('google.fr', params['url'])
        self.assertIn('fr', params['headers']['Accept-Language'])

        dicto['language'] = 'all'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('en', params['headers']['Accept-Language'])
Exemplo n.º 4
0
    def test_request(self):
        query = 'test_query'
        dicto = defaultdict(dict)
        dicto['pageno'] = 1
        dicto['language'] = 'fr_FR'
        params = google.request(query, dicto)
        self.assertIn('url', params)
        self.assertIn(query, params['url'])
        self.assertIn('google.fr', params['url'])
        self.assertIn('fr', params['headers']['Accept-Language'])

        dicto['language'] = 'all'
        params = google.request(query, dicto)
        self.assertIn('google.com', params['url'])
        self.assertIn('en', params['headers']['Accept-Language'])
Exemplo n.º 5
0
    exit(1)

import requests
from json import dumps
from searx.engines import google
from searx.search import default_request_params

request_params = default_request_params()
# Possible params
# request_params['headers']['User-Agent'] = ''
# request_params['category'] = ''
request_params['pageno'] = 1
request_params['language'] = 'en_us'
request_params['time_range'] = ''

params = google.request(argv[1], request_params)

request_args = dict(
    headers=request_params['headers'],
    cookies=request_params['cookies'],
)

if request_params['method'] == 'GET':
    req = requests.get
else:
    req = requests.post
    request_args['data'] = request_params['data']

resp = req(request_params['url'], **request_args)
resp.search_params = request_params
print(dumps(google.response(resp)))