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:
- Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…
- Python: json:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)
- How to Solve Python Error: “HTTP Error 403: Forbidden”
- Python JSON error json.decoder.jsondecodeerror Chinese
- [Solved] TypeError: string indices must be integers, not str
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- python3 are installed through pip on Win 10, Unicode decodeerror: ‘UTF-8’ codec can’t decode byte
- [Solved] JSON check syntax error: json.decoder.JSONDecodeError: Invalid control character at: line 1 column
- Error in reading Chinese path of pydev in eclipse
- Error reporting during installation of node SaaS package