本文整理汇总了Python中searx.url_utils.urlencode函数的典型用法代码示例。如果您正苦于以下问题:Python urlencode函数的具体用法?Python urlencode怎么用?Python urlencode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urlencode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: request
def request(query, params):
offset = (params['pageno'] - 1) * 10
if categories[0] and categories[0] in category_to_keyword:
params['url'] = url.format(keyword=category_to_keyword[categories[0]],
query=urlencode({'q': query}),
offset=offset)
else:
params['url'] = url.format(keyword='web',
query=urlencode({'q': query}),
offset=offset)
# add language tag
if params['language'] == 'no' or params['language'].startswith('no-'):
params['language'] = params['language'].replace('no', 'nb', 1)
if params['language'].find('-') < 0:
# tries to get a country code from language
for lang in supported_languages:
lc = lang.split('-')
if params['language'] == lc[0]:
params['language'] = lang
break
params['url'] += '&locale=' + params['language'].replace('-', '_').lower()
return params
开发者ID:MrLpk,项目名称:searx,代码行数:26,代码来源:qwant.py
示例2: request
def request(query, params):
# obtain token if last update was more than an hour
if time() - (token['last_updated'] or 0) > 3600:
obtain_token()
params['url'] = search_url.format(query=urlencode({'input': query}), token=token['value'])
params['headers']['Referer'] = referer_url.format(query=urlencode({'i': query}))
return params
开发者ID:MrLpk,项目名称:searx,代码行数:8,代码来源:wolframalpha_noapi.py
示例3: _get_url
def _get_url(query, offset, language, time_range):
if time_range in time_range_dict:
return base_url + search_url_with_time.format(offset=offset,
query=urlencode({'p': query}),
lang=language,
age=time_range_dict[time_range][0],
btf=time_range_dict[time_range][1])
return base_url + search_url.format(offset=offset,
query=urlencode({'p': query}),
lang=language)
开发者ID:MrLpk,项目名称:searx,代码行数:10,代码来源:yahoo.py
示例4: _get_url
def _get_url(query, language, offset, time_range):
if time_range in time_range_dict:
search_path = search_string_with_time.format(
query=urlencode({'q': query, 'setmkt': language}),
offset=offset,
interval=time_range_dict[time_range])
else:
search_path = search_string.format(
query=urlencode({'q': query, 'setmkt': language}),
offset=offset)
return base_url + search_path
开发者ID:cy8aer,项目名称:searx,代码行数:11,代码来源:bing_news.py
示例5: request
def request(query, params):
params['url'] = search_url.format(query=urlencode({'q': query}),
api_key=api_key)
params['url'] += '&relevanceLanguage=' + params['language'].split('-')[0]
return params
开发者ID:MrLpk,项目名称:searx,代码行数:7,代码来源:youtube_api.py
示例6: request
def request(query, params):
offset = (params['pageno'] - 1) * number_of_results
string_args = dict(query=urlencode({'srsearch': query}),
offset=offset,
limit=number_of_results,
searchtype=search_type)
format_strings = list(Formatter().parse(base_url))
if params['language'] == 'all':
language = 'en'
else:
language = params['language'].split('-')[0]
# format_string [('https://', 'language', '', None), ('.wikipedia.org/', None, None, None)]
if any(x[1] == 'language' for x in format_strings):
string_args['language'] = language
# write search-language back to params, required in response
params['language'] = language
search_url = base_url + search_postfix
params['url'] = search_url.format(**string_args)
return params
开发者ID:asciimoo,项目名称:searx,代码行数:27,代码来源:mediawiki.py
示例7: request
def request(query, params):
offset = (params['pageno'] - 1) * number_of_results
language = params['language'].replace('-', '_').lower()
if language.split('-')[0] != 'zh':
language = language.split('-')[0]
if params['safesearch'] >= 1:
safesearch = 1
else:
safesearch = 0
# rxieu is some kind of hash from the search query, but accepts random atm
search_path = search_string.format(query=urlencode({'q': query}),
offset=offset,
number_of_results=number_of_results,
rxikd=int(time() * 1000),
rxieu=random.randint(1000000000, 9999999999),
ulse=random.randint(100000000, 999999999),
lang=language,
safesearch=safesearch)
params['url'] = base_url + search_path
return params
开发者ID:cy8aer,项目名称:searx,代码行数:25,代码来源:gigablast.py
示例8: request
def request(query, params):
offset = (params['pageno'] - 1) * 10
language = match_language(params['language'], supported_languages)
language_array = language.split('-')
if params['language'].find('-') > 0:
country = params['language'].split('-')[1]
elif len(language_array) == 2:
country = language_array[1]
else:
country = 'US'
url_lang = 'lang_' + language
if use_locale_domain:
google_hostname = country_to_hostname.get(country.upper(), default_hostname)
else:
google_hostname = default_hostname
# original format: ID=3e2b6616cee08557:TM=5556667580:C=r:IP=4.1.12.5-:S=23ASdf0soFgF2d34dfgf-_22JJOmHdfgg
params['cookies']['GOOGLE_ABUSE_EXEMPTION'] = 'x'
params['url'] = search_url.format(offset=offset,
query=urlencode({'q': query}),
hostname=google_hostname,
lang=url_lang,
lang_short=language)
if params['time_range'] in time_range_dict:
params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
params['headers']['Accept-Language'] = language + ',' + language + '-' + country
params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
params['google_hostname'] = google_hostname
return params
开发者ID:cy8aer,项目名称:searx,代码行数:35,代码来源:google.py
示例9: request
def request(query, params):
offset = (params['pageno'] - 1) * 10
params['url'] = search_url.format(query=urlencode({'q': query}),
offset=offset)
return params
开发者ID:MrLpk,项目名称:searx,代码行数:7,代码来源:mixcloud.py
示例10: request
def request(query, params):
if query.islower():
query = u'{0}|{1}'.format(query.decode('utf-8'), query.decode('utf-8').title()).encode('utf-8')
params['url'] = search_url.format(query=urlencode({'titles': query}),
language=url_lang(params['language']))
return params
开发者ID:asciimoo,项目名称:searx,代码行数:8,代码来源:wikipedia.py
示例11: request
def request(query, params):
locale = match_language(params['language'], supported_languages)
params['url'] = search_url.format(
query=urlencode({'search': query, 'localization': locale}),
pageno=params['pageno'])
return params
开发者ID:cy8aer,项目名称:searx,代码行数:8,代码来源:dailymotion.py
示例12: startpage
def startpage(query, lang):
# startpage autocompleter
url = 'https://startpage.com/do/suggest?{query}'
resp = get(url.format(query=urlencode({'query': query}))).text.split('\n')
if len(resp) > 1:
return resp
return []
开发者ID:MrLpk,项目名称:searx,代码行数:8,代码来源:autocomplete.py
示例13: duckduckgo
def duckduckgo(query, lang):
# duckduckgo autocompleter
url = 'https://ac.duckduckgo.com/ac/?{0}&type=list'
resp = loads(get(url.format(urlencode(dict(q=query)))).text)
if len(resp) > 1:
return resp[1]
return []
开发者ID:MrLpk,项目名称:searx,代码行数:8,代码来源:autocomplete.py
示例14: wikipedia
def wikipedia(query, lang):
# wikipedia autocompleter
url = 'https://' + lang + '.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json'
resp = loads(get(url.format(urlencode(dict(search=query)))).text)
if len(resp) > 1:
return resp[1]
return []
开发者ID:MrLpk,项目名称:searx,代码行数:8,代码来源:autocomplete.py
示例15: request
def request(query, params):
if params['time_range'] and params['time_range'] not in time_range_dict:
return params
offset = (params['pageno'] - 1) * 30
region_code = get_region_code(params['language'], supported_languages)
if region_code:
params['url'] = url.format(
query=urlencode({'q': query, 'kl': region_code}), offset=offset, dc_param=offset)
else:
params['url'] = url.format(
query=urlencode({'q': query}), offset=offset, dc_param=offset)
if params['time_range'] in time_range_dict:
params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])
return params
开发者ID:asciimoo,项目名称:searx,代码行数:18,代码来源:duckduckgo.py
示例16: request
def request(query, params):
offset = (params['pageno'] - 1) * 10
if categories[0] and categories[0] in category_to_keyword:
params['url'] = url.format(keyword=category_to_keyword[categories[0]],
query=urlencode({'q': query}),
offset=offset)
else:
params['url'] = url.format(keyword='web',
query=urlencode({'q': query}),
offset=offset)
# add language tag
language = match_language(params['language'], supported_languages)
params['url'] += '&locale=' + language.replace('-', '_').lower()
return params
开发者ID:cy8aer,项目名称:searx,代码行数:18,代码来源:qwant.py
示例17: request
def request(query, params):
params['url'] = search_url.format(query=urlencode({'q': query}),
api_key=api_key)
# add language tag if specified
if params['language'] != 'all':
params['url'] += '&relevanceLanguage=' + params['language'].split('-')[0]
return params
开发者ID:asciimoo,项目名称:searx,代码行数:9,代码来源:youtube_api.py
示例18: request
def request(query, params):
params['url'] = search_url.format(
category=type_map[params['category']],
q=urlencode({
'q': query,
'page': params['pageno']
})
)
return params
开发者ID:cy8aer,项目名称:searx,代码行数:9,代码来源:findx.py
示例19: get_vqd
def get_vqd(query, headers):
query_url = site_url.format(query=urlencode({'q': query}))
res = get(query_url, headers=headers)
content = res.text
if content.find('vqd=\'') == -1:
raise Exception('Request failed')
vqd = content[content.find('vqd=\'') + 5:]
vqd = vqd[:vqd.find('\'')]
return vqd
开发者ID:asciimoo,项目名称:searx,代码行数:9,代码来源:duckduckgo_images.py
示例20: clean_url
def clean_url(url):
parsed = urlparse(url)
query = [(k, v) for (k, v) in parse_qsl(parsed.query) if k not in ['ixid', 's']]
return urlunparse((parsed.scheme,
parsed.netloc,
parsed.path,
parsed.params,
urlencode(query),
parsed.fragment))
开发者ID:asciimoo,项目名称:searx,代码行数:10,代码来源:unsplash.py
注:本文中的searx.url_utils.urlencode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论