|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- import urllib.parse
- import json
- content = input("qing shu ru:")
- url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'
- head = {}
- head['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0'
- data = {
- "type" : "AUTO",
- "i" : content,
- "doctype" : "json",
- "xmlVersion" : "1.8",
- "keyfrom" : "fanyi.web",
- "ue" : "UTF-8",
- "action" : "FY_BY_CLICKBUTTON",
- "typoResult" : "true"
- }
- data = urllib.parse.urlencode(data).encode('utf-8')
- req = urllib.request.Request(url,data,head)
- response = urllib.request.urlopen(req)
- html = response.read().decode('utf-8')
- target = json.loads(html)
- target = target['translateResult'][0][0]['tgt']
- print(target)
复制代码
为什么会请求来源非法 ,我用鱼C源程序也是这样 一开始以为自己打错或打差 求大神指点一二 万分感谢! |
|