Cách Scrape Dữ Liệu Shopee Với Python (2026)
Shopee là sàn TMĐT lớn nhất Đông Nam Á. Bài viết hướng dẫn scrape sản phẩm Shopee cho nghiên cứu thị trường và theo dõi giá.
Tại Sao Scrape Shopee?
- Theo dõi giá đối thủ
- Phân tích xu hướng sản phẩm
- Nghiên cứu thị trường
- Thu thập reviews
Thách Thức Khi Scrape Shopee
- JavaScript-heavy: Cần headless browser
- Anti-bot: Rate limiting, CAPTCHA
- Dynamic content: Data load bằng API
Phương Pháp 1: API Approach
Shopee có internal API, dễ scrape hơn HTML:
import requests
# Shopee search API
url = "https://shopee.vn/api/v4/search/search_items"
params = {
"keyword": "iphone",
"limit": 50,
"newest": 0
}
headers = {
"User-Agent": "Mozilla/5.0...",
"Referer": "https://shopee.vn"
}
response = requests.get(url, params=params, headers=headers)
data = response.json()
for item in data['items']:
print(item['name'], item['price'])
Phương Pháp 2: Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://shopee.vn/search?keyword=iphone")
# Wait for products to load
import time
time.sleep(3)
products = driver.find_elements(By.CSS_SELECTOR, ".shopee-search-item-result__item")
for p in products:
title = p.find_element(By.CSS_SELECTOR, "div._1NoI8_").text
price = p.find_element(By.CSS_SELECTOR, "span._29R_un").text
print(title, price)
driver.quit()
Tips Tránh Bị Block
- Rate limiting: 1-2 giây delay giữa requests
- Rotate User-Agent: Dùng nhiều UA khác nhau
- Proxy: Đổi IP thường xuyên
- Sessions: Giả lập user sessions
Dữ Liệu Có Thể Thu Thập
- Tên sản phẩm
- Giá gốc, giá sale
- Số lượng bán
- Rating và reviews
- Thông tin shop
VinaProxy + Shopee Scraping
- IP Việt Nam – không bị geo-block
- Residential IP tránh detection
- Giá chỉ $0.5/GB
