|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
根据小甲鱼爬有道翻译的代码,data变了:
import urllib.request
import urllib.parse
url = 'http://fanyi.youdao.com/'
data = {}
data['i'] = '哈哈'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '15977568063610'
data['sign'] = 'c132ec5ca3a7623a8028b683eafa4ecc'
data['lts'] = '1597756806361'
data['bv'] = '94d04da9bee8870ad9ad8714b54f2bea'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url,data)
html = response.read().decode('utf-8')
print(html)
………………………………运行结果刚开始不报错,后面报错了…………………………
import json
>>> json.loads(html)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
json.loads(html)
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
想知道报错原因和改进措施 |
|