本帖最后由 thepoy 于 2020-8-11 21:49 编辑
requests的post方法可以实现你的要求,具体怎么用可以参考官方文档,给你一段示例代码:
[Python] 纯文本查看 复制代码 Form_Data={}
Form_Data['i'] = e
Form_Data['from'] = 'AUTO'
Form_Data['to'] = 'AUTO'
Form_Data['smartresult'] = 'dict'
Form_Data['client'] = client
Form_Data['salt'] = salt
Form_Data['sign'] = sign
Form_Data['ts'] = ts
Form_Data['bv'] = bv
Form_Data['doctype'] = 'json'
Form_Data['version'] = '2.1'
Form_Data['keyfrom'] = 'fanyi.web'
Form_Data['action'] = 'FY_BY_CLICKBUTTION'
'''
长词典用下面这个办法更好看一些,代码量也能少一些
Form_Data = {
'i':e,
'from':'AUTO',
...
'action':'FY_BY_CLICKBUTTION'
}
'''
translate_result = requests.request(method='POST', url=url, data=Form_Data, headers=headers).text # 等同中requests.post(*args, *kwargs)
文件上传参考中文文档:https://requests.readthedocs.io/zh_CN/latest/user/quickstart.html#post-multipart-encoded |