用python写网络爬虫-英文翻译

今天学模拟登陆结果发现微博这个鬼东西登陆有点复杂,用户名base64加密不说,密码rsa加密。。。。。。搞得我头晕死了。实在没办法,5分钟写个英文翻译休息下。用的是百度翻译

# -*- coding:UTF8 -*-
import urllib.request
import urllib.parse
import json

english=input('plz input english you want to translate:')
url='http://fanyi.baidu.com/v2transapi'
headers={'User-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
data={}
data['from']='en'
data['to']='zh'
data['query']=english
data['transtype']='translang'
data['simple_means_flag']='3'
encoded_data=urllib.parse.urlencode(data).encode('UTF8')
request=urllib.request.Request(url,encoded_data,headers=headers)
html=urllib.request.urlopen(request).read()
response_dic=json.loads(html)
print(english+':'+response_dic['trans_result']['data'][0]['dst'])

你可能感兴趣的:(python)