From 93481554a4b7dae37703ec27fcaae87679f73c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A9=E6=88=90?= <1911560341@qq.com> Date: Tue, 19 Sep 2023 02:00:49 +0000 Subject: [PATCH] =?UTF-8?q?=E7=88=AC=E8=99=AB=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏天成 <1911560341@qq.com> --- ...54\344\270\234\347\210\254\350\231\253.py" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "20210340639\345\244\217\345\244\251\346\210\220/\347\210\254\350\231\253/\344\272\254\344\270\234\347\210\254\350\231\253.py" diff --git "a/20210340639\345\244\217\345\244\251\346\210\220/\347\210\254\350\231\253/\344\272\254\344\270\234\347\210\254\350\231\253.py" "b/20210340639\345\244\217\345\244\251\346\210\220/\347\210\254\350\231\253/\344\272\254\344\270\234\347\210\254\350\231\253.py" new file mode 100644 index 0000000..5b4cc17 --- /dev/null +++ "b/20210340639\345\244\217\345\244\251\346\210\220/\347\210\254\350\231\253/\344\272\254\344\270\234\347\210\254\350\231\253.py" @@ -0,0 +1,39 @@ +import requests +import csv +from time import sleep +import random + +def main(page,f): + url = 'https://club.jd.com/comment/productPageComments.action' + params = { + 'productId': 100011483893, + 'score': 0, + 'sortType': 5, + 'page': page, + 'pageSize': 10, + 'isShadowSku': 0, + 'fold': 1 + } + headers = { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.35 Safari/537.36', + 'referer': 'https://item.jd.com/' + } + resp = requests.get(url,params=params,headers=headers).json() + comments = resp['comments'] + for comment in comments: + content = comment['content'] + content = content.replace('\n','') + comment_time = comment['creationTime'] + score = comment['score'] + print(score,comment_time,content) + csvwriter.writerow((score,comment_time,content)) + print(f'第{page+1}页爬取完毕') + +if __name__ == '__main__': + with open('04.csv','a',encoding='utf-8',newline='')as f: + csvwriter = csv.writer(f) + csvwriter.writerow(('评分','评论时间','评论内容')) + for page in range(15): + main(page,f) + sleep(5+random.random()) + -- Gitee