json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

上篇博客提到了爬取动态数据,但是在构造request_url时,其中的url我用的浏览器的网址,但是经过运行发现,有时可以运行成功,有时

request_url = "http://tool.manmanbuy.com/history.aspx?DA=1&action=gethistory&url={0}&bjid=&spbh=&cxid=&zkid=&w=951&token={1}".format(url, token)
data = requests.get(request_url)
history_price = json.loads(data.text)[‘datePrice‘]

Traceback (most recent call last):
File “D:/spider/product.py”, line 4, in
res = json.loads(file.text)
File “C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\json_init_.py”, line 348, in loads
return _default_decoder.decode(s)
File “C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\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)

会在第三行代码报错,也就是json.loads()位置。

原因:

  request_url不正确,使用浏览器中的网址作为url是不太规范的,所以我们尽量找到request_url中url部分的生成机制,构造出正确的request_url吧!

我在网页的源代码中,找到了url的生成机制,以及在div中找到了生成的url。

这样就能通过获取这个位置的url来构造request_url啦!

原文地址:https://www.cnblogs.com/qilin20/p/12276086.html

时间: 2024-08-29 10:00:21

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)的相关文章

python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决

有如下一个文件,内容如下 { "test1": "/root/test/test1.template", "test2": "/root/test/test2.template", "test3": "/root/test/test3.template", "test4": "/root/test/test4.template", "te

python中报错"json.decoder.JSONDecodeError: Expecting value:"的解决

在学习python语言中用json库解析网络数据时,我遇到了两个编译错误:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:和json.decoder.JSONDecodeError: Expecting value:.费了一些时间才找到原因,在此记录总结,希望能对学习python的同学有所帮助. 我运行的程序初始如下: import json data=''' { 'name' : '

json.loads 报错 json.decoder.JSONDecodeError

json.loads报json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes 出现这个错误其实只需要知道一点就能解决,那就是这个数据结构不符合json标准格式  """ 1. 标准JSON的合法符号:{  }  "  : , [  ] ----> 即:左大括号,右大括号,双引号,冒号,逗号,左中括号 和 右中括号 2. JSON布尔:必须小写的true和fa

jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data 我在使用$.parseJSON解析后台返回的JSON的数据时,出现了这样的错误,我还以为返回的JSON格式出现了错误,因为JSON要求格式非常严格.最后发现JSON格式没有太明显的格式错误,我使用fastJSON来生成的JSON格式数据,原来是因为数据已经是一个JavaScript对象了,所以在进行解析就会出错了 我直接将这段数据al

ValueError: Expecting property name: line 1 column 2 (char 1)

代码: import json str2 = '{"domain":"456"}' str1 = "{'domain':'123'}" print json.loads(str2) print json.loads(str1) python json.loads() 标准的书写键与值 ,以双引号作为解析标准.单引号则会报错. 原文地址:https://www.cnblogs.com/qxh-beijing2016/p/11693045.html

js - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data jquery-1.9.1.min.js:3:4315

FF中时不时报这个错, 就近段做项目来看,  一般是我通过 jquery获取form中的参数(或直接获取参数,并通过ajax进行异步请求的时候,如果有错,就抱该错误! 而对应的, 如果在 Google chrome中, 则会报: Uncaught SyntaxError: Unexpected token < 我觉得Google chrome的这个错, 有点不太准确. 虽然题目中的错误, 很泛, 但是就近段做项目来说, 大致就是这样. 其实可以分很多种类型的 "错误请求参数":包

python遇坑记录-json.loads() :JSONDecodeError: Invalid \escape

环境:python3.6 json文件: { "src_dir" : "C:\\Users\\admin\\Desktop\\99\\apkobb", "bucket" : "tocggspace", "key_prefix" : "ggspace/self/" } py文件: import sys, json configfile = sys.argv[1] config = json

SyntaxError: JSON.parse: bad control character in string literal at line 1 column 16 of the JSON data

JSON.parse转化Json字符串时出现:SyntaxError: JSON.parse: bad control character in string literal at line 1 column 16 of the JSON data 测试代码: JSON.parse("{\"Result\":\"bhbh\thuhuha\"}") 罪魁祸首:\t导致

微信小程序云开发导入json数据报错:导入数据库失败, Error: Poll error, 导入数据任务(id:528440)异常,错误信息:line 1, column 750: bare &quot; in non-quoted-field

错误信息如下: 导入数据库失败, Error: Poll error, 导入数据任务(id:528440)异常,错误信息:line 1, column 750: bare " in non-quoted-field 导入数据库失败, Error: Poll error, 导入数据任务(id:528445)异常,错误信息:解析json文档错误,请检查导入文件格式,错误详情如下:invalid character ',' looking for beginning of value 导入JSON格式