#京東華為P30 Pro評(píng)論
import requests
import json
import time
headers = {
??? 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}
urls = ['https://sclub.jd.com/comment/productPageComments.action?productId=100004404948&score=0&sortType=5&page={}&pageSize=10'.format(str(i)) for i in range(0,2)]
for url in urls:
? res = requests.get(url,headers=headers)
? json_data = json.loads(res.text)
? comments = json_data['comments']
? for comment in comments:
??? content = comment['content']
??? creationTime = comment['creationTime']
??? nickname = comment['nickname']
??? productColor = comment['productColor']
??? print(content,creationTime,nickname,productColor)
? time.sleep(5)
##一直報(bào)錯(cuò)办龄,信息如下:
D:\Python\PycharmProjects\venv\Scripts\python.exe D:/Python/PycharmProjects/TMP.py
Traceback (most recent call last):
File "D:/Python/PycharmProjects/TMP.py", line 12, in
json_data = json.loads(res.text)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\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)
Process finished with exit code 1