python爬取京東評論 一

2021-09-30 20:23:03 字數 1628 閱讀 2705

作為乙個爬蟲小白解決問題是十分蛋疼的(φ皿φ),就這幾行**,我折磨了一下午,然後我發現,學習**最大的難題是學習資源獲取的途徑並不是**本身,只要學,任何人都能學會

開發者選項

3.知道了這個是相應的請求了,去headers弄url,去看看怎麼樣

複製url

4下面開始搞**

import requests

import json

url = ''

res = requests.get(url,headers=headers)

jd=json.loads(res.text.lstrip('fetchjson_comment98vv12345(').rstrip(');'))

#上面這行真是讓我蛋疼半天的元首,記住要去掉無關字元

com_list=jd['comments']

for i in com_list:

print(i['content'])

心路歷程:我之前爬過幾個動態頁面沒遇到過這種問題,一開始我沒去掉,一直報這種錯

e:\python3\python.exe f:/pycharm/untitled/cpu.py

traceback (most recent call last):

file "f:/pycharm/untitled/cpu.py", line 12, in sd = json.loads(res)

file "e:\python3\lib\json\__init__.py", line 354, in loads

return _default_decoder.decode(s)

file "e:\python3\lib\json\decoder.py", line 339, in decode

obj, end = self.raw_decode(s, idx=_w(s, 0).end())

file "e:\python3\lib\json\decoder.py", line 357, in raw_decode

raise jsondecodeerror("expecting value", s, err.value) from none

json.decoder.jsondecodeerror: expecting value: line 1 column 1 (char 0)

python爬取京東評論

這不是我的第乙個爬蟲,但大多數都是像這樣簡單粗暴的,因為一開始對於定義函式,然後再進行相應的操作,是比較困難的,這能直接寫for迴圈語句。然後,我們便開始進行相應的爬蟲第一步 匯入必要的包 import requests import json header這個的作用在於偽裝成瀏覽器進行操作,有些網...

用Python爬取京東手機評論

好評 中評 差評 追評 可以看到這個url裡都有以下幾個引數 videocount 2638,videocountstr 2600 aftercount 4852,aftercountstr 4800 showcount 24200,showcountstr 2.4萬 productid 10000...

京東爬取評論簡單分析

def get comment url i 0 while true url str i pagesize 10 isshadowsku 0 fold 1 headers response requests.get url,headers headers comment list re.compil...