gonorth 发表于 2020-10-21 14:36:50

python55讲中的使用代理问题

我用代理的方式访问网站,却无回馈,麻烦帮看下代码,看看是不是使用代理的语句有问题,还是说网站屏蔽这个代理访问。谢谢
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']['tgt'] )

wp231957 发表于 2020-10-21 14:46:39

不花银子的代理就是个扯

gonorth 发表于 2020-10-21 15:20:37

wp231957 发表于 2020-10-21 14:46
不花银子的代理就是个扯

意思是写的没问题,代理有问题呗
页: [1]
查看完整版本: python55讲中的使用代理问题