Backend Development 7 min read

How to Scrape JD.com Product Reviews with Python and Save to CSV

This tutorial explains how to use Python to scrape product reviews from JD.com via its AJAX comment API, extract fields such as nickname, score, content, and image count, and save the collected data into a CSV file using the requests and csv modules.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
How to Scrape JD.com Product Reviews with Python and Save to CSV

In e‑commerce platforms, user reviews are valuable data; this article demonstrates how to crawl product reviews from JD.com using Python and store them in a CSV file.

Prerequisites: install the Python libraries requests , csv , json , and time (e.g., pip install requests ).

The JD review endpoint is https://club.jd.com/comment/productPageComments.action , which accepts parameters such as productId , score , sortType , page , pageSize , isShadowSku , and fold .

The script creates a CSV file with headers nickname, score, content, productColor, creationTime, imageCount and iterates over scores 1‑5 and the first five pages for each score, sending GET requests with appropriate headers.

# 创建文件对象
f = open('data.csv', mode='w', encoding='utf-8-sig', newline='')
csv_writer = csv.DictWriter(f, fieldnames=['nickname','score','content','productColor','creationTime','imageCount'])
csv_writer.writeheader()
headers = {'User-Agent': 'Mozilla/5.0 ...'}
base_url = 'https://club.jd.com/comment/productPageComments.action'
for score in range(1,6):
params = {'productId':'100142621600','score':score,'sortType':5,'page':0,'pageSize':10,'isShadowSku':0,'fold':1}
for page in range(1,6):
params['page'] = page
response = requests.get(base_url, params=params, headers=headers)
if response.status_code != 200: continue
comments = response.json()['comments']
for index in comments:
dit = {'nickname': index.get('nickname',''), 'score': index.get('score',''), 'content': index.get('content',''), 'productColor': index.get('productColor',''), 'creationTime': index.get('creationTime',''), 'imageCount': len(index.get('images',[]))}
csv_writer.writerow(dit)
print(dit)
time.sleep(1)
f.close()

After execution, the CSV file contains the extracted review data, and the console prints each record; a sample screenshot of the result is shown in the original article.

PythonData ExtractionCSVWeb ScrapingRequestsJD.com
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.