文章目录
前言
我们在编写爬虫代码的时候,都需要去请求链接,有事还需要一连串的参数,这时候我们是不可能一个一个手打上去的,这次就分享一个快速解析请求的小工具
二、地址
https://curl.trillworks.com/
三、用法
3.1这里以有道翻译为例,右键链接>copy>copy as curl(bash)
3.2 黏贴到上面的网站,右侧方框会自动填充requests请求
import requests
cookies = {
'_ntes_nnid': '4306b0cea1d4764dd96cf0c847050fac,1576646420094',
'OUTFOX_SEARCH_USER_ID_NCOO': '4184037.7959246757',
'OUTFOX_SEARCH_USER_ID': '[email protected]',
'_ga': 'GA1.2.791167137.1585901905',
'JSESSIONID': 'aaakdOPH8qCyN4dZE5gwx',
'___rl__test__cookies': '1604288562645',
}
headers = {
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://fanyi.youdao.com',
'Referer': 'http://fanyi.youdao.com/',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
params = (
('smartresult', ['dict', 'rule']),
)
data = {
'i': '\u722C\u866B',
'from': 'AUTO',
'to': 'AUTO',
'smartresult': 'dict',
'client': 'fanyideskweb',
'salt': '16042885626485',
'sign': '36adc2c6f5c2fc16ca9de3d26a966769',
'lts': '1604288562648',
'bv': '8269b35cc1594b7635631cdd3a301112',
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_REALTlME'
}
response = requests.post('http://fanyi.youdao.com/translate_o', headers=headers, params=params, cookies=cookies, data=data, verify=False)
#NB. Original query string below. It seems impossible to parse and
#reproduce query strings 100% accurately so the one below is given
#in case the reproduced version is not "correct".
# response = requests.post('http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule', headers=headers, cookies=cookies, data=data, verify=False)
总结
怎么样,这样是不是很方便,然后有道翻译请求参数是有加密的,破解方法在我这篇博客里https://blog.csdn.net/qq_26079939/article/details/109444794