有道翻译信息爬取。
import urllib.request import json # 百度翻译 # url = 'https://fanyi.baidu.com/v2transapi?from=zh&to=en' # # a = input("请输入需要翻译的内容:") # data = {} # data['from'] = 'zh' # data['to'] = 'en' # data['query'] = a # data['transtype'] = 'realtime' # data['simple_means_flag'] = '3' # data['sign'] = '993764.772821' # data['domain'] = 'common' # # data = urllib.parse.urlencode(data).encode('utf-8') # response = urllib.request.urlopen(url,data) # # html = response.read().decode('utf-8') # # a = json.loads(html)['data'][0]['v'] # print(a) # # 有道翻译 url1 = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' a1 = input("请输入需要翻译的内容:") data1 = {} data1['i'] = a1 data1['type'] = 'AUTO' data1['doctype'] = 'json' data1['xmlVersion'] = '1.6' data1['keyfrom'] = 'fanyi.web' data1['ue'] = 'utf-8' data1['typoResult'] = 'true' data1 = urllib.parse.urlencode(data1).encode('utf-8') response = urllib.request.urlopen(url1,data1) html1 = response.read().decode('utf-8') b1 = json.loads(html1)['data'][0]['v'] print(b1)