一.实时爬取有道上翻译内容:
idea:模拟请求,解析返回值
code:
importurllib.request
importurllib.parse
importjson
a =5000
whilea >:
txt =input('输入要翻译的内容:')
iftxt =='0':
break
else:
url ='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link'
data = {
'from':'AUTO',
'to':'AUTO',
'smartresult':'dict',
'client':'fanyideskweb',
'salt':'1525446908425',
'sign':'c50721aafc8755e398f24f093a0f0026',
'doctype':'json',
'version':'2.1',
'keyfrom':'fanyi.web',
'action':'FY_BY_REALTIME',
'typoResult':'false'}
data['i'] = txt
data = urllib.parse.urlencode(data).encode('utf - 8')
wy = urllib.request.urlopen(url,data)
html = wy.read().decode('utf - 8')
ta = json.loads(html)
print('翻译结果: %s '% (ta['translateResult'][][]['tgt']))
a = a -1
测试:
code传送门:https://github.com/ddyin/youdaoTranslate
领取专属 10元无门槛券
私享最新 技术干货