python爬京東評論


我,找回,密碼了!

https://blog.csdn.net/weixin_42590877/article/details/99686720?tdsourcetag=s_pcqq_aiomsg

就是這個網址助我!

這個是我要爬的,看着暖和 https://item.jd.com/33919692427.html

# In[sy_final]:
#!/usr/bin/python
import requests
import json

#這個headers害慘了我,一定要有referer才可以運行
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
'Referer': 'https://item.jd.com/33919692427.html'
}

#這個url備用
url = 'https://sclub.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv382&productId=33919692427&score=0&sortType=5&page=0&pageSize=10&isShadowSku=0&fold=1'
file = open("E:\\2020期末復習\\python\\軍大衣前20頁評論2.txt","w"); #打開一個文件
for i in range(20): #假定爬20頁
url = 'https://sclub.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv382&productId=33919692427&score=0&sortType=5&page=%d&pageSize=10&isShadowSku=0&fold=1' % i
r = requests.get(url,headers=headers)
#jd = json.loads(r.text.lstrip('fetchJSON_comment98vv382(').rstrip(');'))
#jd = json.loads(r.text)
jd = json.loads(r.text.strip('fetchJSON_comment98vv382();'))
com_list=jd['comments']
for j in com_list:
file.write(j['content']); #寫入內容
print(j['content']);
file.write('\r\n'); #換行
file.close


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM