鱼C论坛

 找回密码
 立即注册
查看: 1032|回复: 0

python爬虫类问题

[复制链接]
发表于 2020-8-18 22:07:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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)
想知道报错原因和改进措施
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-19 11:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表