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

The last blog mentioned crawling dynamic data, but in the construction of request_ URL, the URL of which I use the browser’s web address, but after running found that sometimes can run successfully, sometimes

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)

It will report an error in the third line of code, which is the json.loads() position.

Reason.

The request_url is not correct, using the URL in the browser as the url is not very standard, so let’s try to find the generation mechanism of the url part in the request_url and construct the correct request_url!

I found the url generation mechanism in the source code of the page, as well as the generated url in the div.

This way you can construct the request_url by getting the url of this location!

Similar Posts: