|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我用代理的方式访问网站,却无回馈,麻烦帮看下代码,看看是不是使用代理的语句有问题,还是说网站屏蔽这个代理访问。谢谢
import urllib.request
import urllib.parse
import json
content = input('plz input the content needs to be translate:')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = dict ()
data ['i'] = content
data ['from'] = 'AUTO'
data['to'] = 'AUTO'
data [ 'doctype'] = 'json'
data['lts'] = '1603255187388'
data ['bv'] ='02edb5d6c6ac4286cd4393133e5aab14'
data ['sign'] = 'c9226d73895eabbc3e4b3daed7dd64f2'
data ['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data ['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data ['action'] = 'FY_BY_CLICKBUTTION'
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url,data)
proxy_support = urllib.request.ProxyHandler({'http':"103.148.50.54:8080"})
opener = urllib.request.build_opener(proxy_support)
opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit11111111111111111111111111111111')] #这里我就不po出来了。。。
response = opener.open(req)
html = response.read().decode('utf-8')
print (html)
html = json.loads(html)
print ('result:%s' % html['translateResult'][0][0]['tgt'] ) |
|