|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是网页获取的信息,上图中的Request Method是POST,程序运行结果是正确的
- import urllib.request as r
- import urllib.parse as p
- import json
- content = input('请输入要翻译的内容:')
- url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.sogou.com/sie'
- data = {}
- data['i'] = content
- data['from'] = 'AUTO'
- data['to'] = 'AUTO'
- data['smartresult'] = 'dict'
- data['client'] = 'fanyideskweb'
- data['salt'] = '1493279538015'
- data['sign'] = '8823988ceacf755c48049488b61f360e'
- data['doctype'] = 'json'
- data['version'] = '2.1'
- data['keyfrom'] = 'fanyi.web'
- data['action'] = 'FY_BY_CLICKBUTTON'
- data['typoResult'] = 'true'
- data = p.urlencode(data).encode('utf-8')
- response = r.urlopen(url, data)
- html = response.read( ).decode('utf-8')
- target = json.loads(html)
- print('翻译结果:%s' % (target['translateResult'][0][0]['tgt']))
复制代码
但是上午一直没找到Post,只有Get,程序一直报错,
求问:实现这个功能时Request Method必须是POST吗? |
|