コード例 #1
0
ファイル: google_news.py プロジェクト: soapy2018/searx
def request(query, params):
    """Google-News search request"""

    language, country, lang_country = get_lang_country(
        # pylint: disable=undefined-variable
        params, supported_languages, language_aliases
    )
    subdomain = 'news.google.com'

    if params['time_range']: # in time_range_dict:
        query += ' ' + time_range_dict[params['time_range']]

    query_url = 'https://'+ subdomain + '/search' + "?" + urlencode({
        'q': query,
        'hl': language,
        'lr': "lang_" + language,
        'ie': "utf8",
        'oe': "utf8",
        'ceid' : "%s:%s" % (country, language),
        'gl' : country,
    })

    if params['safesearch']:
        query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})

    params['url'] = query_url
    logger.debug("query_url --> %s", query_url)

    # en-US,en;q=0.8,en;q=0.5
    params['headers']['Accept-Language'] = (
        lang_country + ',' + language + ';q=0.8,' + language + ';q=0.5'
        )
    logger.debug("HTTP header Accept-Language --> %s",
                 params['headers']['Accept-Language'])
    params['headers']['Accept'] = (
        'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
        )

    # hl=en redirect to hl=en-US / en-CA ...
    params['soft_max_redirects'] = 1

    #params['google_subdomain'] = subdomain

    return params
コード例 #2
0
def request(query, params):
    """Google-Video search request"""

    language, country, lang_country = get_lang_country(
        # pylint: disable=undefined-variable
        params,
        supported_languages,
        language_aliases,
    )
    subdomain = "www." + google_domains.get(country.upper(), "google.com")

    query_url = ("https://" + subdomain + "/search" + "?" +
                 urlencode({
                     "q": query,
                     "tbm": "isch",
                     "hl": lang_country,
                     "lr": "lang_" + language,
                     "ie": "utf8",
                     "oe": "utf8",
                     "num": 30,
                 }))

    if params["time_range"] in time_range_dict:
        query_url += "&" + urlencode(
            {"tbs": "qdr:" + time_range_dict[params["time_range"]]})
    if params["safesearch"]:
        query_url += "&" + urlencode(
            {"safe": filter_mapping[params["safesearch"]]})

    params["url"] = query_url
    logger.debug("query_url --> %s", query_url)

    params["headers"]["Accept-Language"] = "%s,%s;q=0.8,%s;q=0.5" % (
        lang_country,
        language,
        language,
    )
    logger.debug("HTTP Accept-Language --> %s",
                 params["headers"]["Accept-Language"])
    params["headers"][
        "Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    # params['google_subdomain'] = subdomain
    return params
コード例 #3
0
def request(query, params):
    """Google-Video search request"""

    language, country, lang_country = get_lang_country(
        # pylint: disable=undefined-variable
        params,
        supported_languages,
        language_aliases)
    subdomain = 'www.' + google_domains.get(country.upper(), 'google.com')

    query_url = 'https://' + subdomain + '/search' + "?" + urlencode(
        {
            'q': query,
            'tbm': "isch",
            'hl': lang_country,
            'lr': "lang_" + language,
            'ie': "utf8",
            'oe': "utf8",
            'num': 30,
        })

    if params['time_range'] in time_range_dict:
        query_url += '&' + urlencode(
            {'tbs': 'qdr:' + time_range_dict[params['time_range']]})
    if params['safesearch']:
        query_url += '&' + urlencode(
            {'safe': filter_mapping[params['safesearch']]})

    params['url'] = query_url
    logger.debug("query_url --> %s", query_url)

    params['headers']['Accept-Language'] = ("%s,%s;q=0.8,%s;q=0.5" %
                                            (lang_country, language, language))
    logger.debug("HTTP Accept-Language --> %s",
                 params['headers']['Accept-Language'])
    params['headers']['Accept'] = (
        'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    )
    # params['google_subdomain'] = subdomain
    return params