当前位置: 首页 > 工具软件 > jd2xx > 使用案例 >

记录一下JD爬商品评论的过程

太叔正文
2023-12-01

 

需求是爬商品的好中差评以及追评,并存入MySQL

满满的干货,直接上代码,伸手党修改一下逻辑、参数可用

由于会检测IP,频繁抓取会短时间屏蔽IP,这里使用了快代理动态获取IP,我用的是时效一分钟的IP,这种写法比较浪费,可以自行修改

import re
import requests
import json
import pymysql
from datetime import datetime
import random

# JD商品类型
# score=0 全部商品  score=1差评   score=2中评  score=3好评  score=4晒图   score=5追评  score=7视频晒单
# sortType=5 默认排序  sortType=6时间排序

product_id = "XX"  # jd商品 编号
score_list = [1,2,3,5]  # 取差评,中评,好评的数据
number = 0


# 取商品评论方法 参数-起始页数-最大页数-商品id-评价类型
def SaveCommentData(minIndex,maxIndex,productId,i):

    scoreTypeSelect = i
    try:
        url = "https://club.jd.com/comment/skuProductPageComments.action?callback=fetchJSON_comment98&productId=" + product_id + "&score=" + str(scoreTypeSelect) + "&sortType=5&page={}&
 类似资料: