Skip to content

Commit 9667fa4

Browse files
author
刘昊
committed
jd goods comment
1 parent ae76fb4 commit 9667fa4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

jd.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# coding:utf-8
3+
import json
4+
import requests
5+
import time
6+
current_page = 0;
7+
end_page = 100
8+
base_url = 'https://club.jd.com/comment/productPageComments.action?productId=3867555&score=0&sortType=5&pageSize=10&isShadowSku=0&rid=0&fold=1'
9+
custom_header = {
10+
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
11+
'Cookie':'TrackID=1tZQPZprEeMnQAs2UupqrhskTeQ6veeQw7p_mwNuHR_scD1E1LE1pvI9rTCyUYGbjMckghzFFQ8sQQ02H97WumEGZqfppLGXyz1UZ1TrGu55JDzin4Bin7LmAgzgNixVk; pinId=tqSDXi4Wz7jtMjzhrVXbUw; unpl=V2_ZzNtbUADRUYhDUIBf0tVBWJUR10RVRNFJgpFV3gRX1ZlVxoKclRCFXMUR1NnGlQUZwcZX0ZcQxRFCHZXchBYAWcCGllyBBNNIEwHDCRSBUE3XHxcFVUWF3RaTwEoSVoAYwtBDkZUFBYhW0IAKElVVTUFR21yVEMldQl2V3oeWwxmARVVSmdzEkU4dlR9G1kDYTMTbUNnAUEpC0BQcx9USGQCFVpLVkESfQB2VUsa; __jdv=122270672|baidu|-|organic|not set; ipLoc-djd=1-72-2799-0; __jda=122270672.2066803699.1469756424.1498721740.1499838848.19; __jdb=122270672.9.2066803699|19.1499838848; __jdc=122270672; 3AB9D23F7A4B3C9B=3F52EDASMTDIDSLSXWIOQZYH3ZAZLUZHQZTT56LGRBAHRNIKIY77GW2AXXX5KPAIKHT72LTAAVMBNJNK2SU764UUXM; __jdu=2066803699'
12+
}
13+
def fetchCommentJSON():
14+
global current_page
15+
current_page += 1
16+
if current_page < end_page:
17+
print current_page
18+
target_url = base_url+'&page='+str(current_page)
19+
response = requests.get(target_url,headers = custom_header)
20+
if response.status_code == 200:
21+
result = response.text
22+
try:
23+
goods = json.loads(result.encode('utf-8'))
24+
if len (goods['comments']) > 0:
25+
for comment in goods['comments']:
26+
print comment['content']
27+
except ValueError:
28+
print 'error'
29+
30+
time.sleep(1)
31+
fetchCommentJSON()
32+
33+
if __name__== '__main__':
34+
fetchCommentJSON()

0 commit comments

Comments
 (0)