|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
两段代码爬的咋不一样啊? 一个把整个网页都弄下来了。
是字典的问题吗?
import urllib.request
import urllib.parse
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {
'i': '你好',
'from': 'AUTO',
'to': 'AUTO',
'smartresult': 'dict',
'client': 'fanyideskweb',
'salt': '15830270361564',
'sign': '722c486628af34b85df217c4fe6b111a',
'ts': '1583027036156',
'bv': '0ed2e07b89acaa1301d499442c9fdf79',
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_REALTlME'}
print(data)
data = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url,data)
html = response.read().decode('utf-8')
print(html)
import urllib.request
import urllib.parse
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data={}
data['i']='你好'
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']='15830270361564'
data['sign']='722c486628af34b85df217c4fe6b111a'
data['ts']='1583027036156'
data['bv']='0ed2e07b89acaa1301d499442c9fdf79'
data['doctypt']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_REALTlME'
print(data)
data=urllib.parse.urlencode(data).encode('utf-8')
response =urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')
print(html)
|
|