Scraping APITính năngCạo Shopee

Thu thập dữ liệu trang web Shopee

Giải thích tham số

Tham sốKiểu dữ liệuGiá trịMô tả
actorstringscraper.shopeeMục nhập cố định
input.actionstringshopee.productHỗ trợ ba loại:
  1. shopee.product Lấy dữ liệu chi tiết sản phẩm
  2. shopee.search Dữ liệu tìm kiếm từ khóa
  3. shopee.live Dữ liệu liên quan đến livestream | | input.url | string | Liên kết URL | Hỗ trợ bốn loại liên kết URL:
  4. Liên kết URL của trang chi tiết sản phẩm
  5. Liên kết API của trang chi tiết sản phẩm (/api/v4/pdp/get_pc)
  6. Liên kết API để tìm kiếm sản phẩm (/api/v4/search/search_items)
  7. Liên kết API cho phát trực tiếp (/api/v1/session/{sessionId}/more_items) |

Dữ liệu chi tiết sản phẩm

import requests
import json
 
API_KEY = ""
host = "api.scrapeless.com"
url = f"https://{host}/api/v1/scraper/request"
 
payload = json.dumps({
   "actor": "scraper.shopee",
   "input": {
      "action": "shopee.product",
      "url": "https://shopee.tw/2312312.10228173.24803858474"
   }
})
headers = {
   'Content-Type': 'application/json',
   'x-api-token': f'{API_KEY}'
}
 
response = requests.request("POST", url, headers=headers, data=payload)
 
print(response.text)
 

Dữ liệu tìm kiếm sản phẩm

import requests
import json
 
API_KEY = ""
host = "api.scrapeless.com"
url = f"https://{host}/api/v1/scraper/request"
 
payload = json.dumps({
   "actor": "scraper.shopee",
   "input": {
      "action": "shopee.search",
      "url": "https://shopee.co.th/api/v4/search/search_items?by=sales&keyword=baby%20pants&limit=30&newest=0&order=desc&page_type=search"
   }
})
headers = {
   'Content-Type': 'application/json',
   'x-api-token': f'{API_KEY}'
}
 
response = requests.request("POST", url, headers=headers, data=payload)
 
print(response.text)
 

Dữ liệu Livestream

import requests
import json
 
API_KEY = ""
session_id = ""
host = "api.scrapeless.com"
url = f"https://{host}/api/v1/scraper/request"
 
payload = json.dumps({
   "actor": "scraper.shopee",
   "input": {
      "action": "shopee.live",
      "url": f"https://live.shopee.co.th/api/v1/session/{session_id}/more_items?offset=0&limit=10"
   }
})
headers = {
   'Content-Type': 'application/json',
   'x-api-token': f'{API_KEY}'
}
 
response = requests.request("POST", url, headers=headers, data=payload)
 
print(response.text)
 

Cách xây dựng liên kết API

API trang chi tiết sản phẩm

# API có thể được chia thành ba phần
# 1. region
# 2. item_id
# 3. shop_id
 
# Danh sách region được hỗ trợ
# ["shopee.co.id", "shopee.vn", "shopee.co.th", "shopee.ph", "shopee.com.my", "shopee.sg", "shopee.com.co", "shopee.cl", "shopee.com.mx", "shopee.com.br", "shopee.tw"]
 
url = f"https://{region}/api/v4/pdp/get_pc?item_id={item_id}&shop_id={shop_id}"
print(url)

API tìm kiếm sản phẩm

limit = 20  # 10 20 30 40
order = "desc"
page_type = "search"
keyword = "keyword"   # chỉnh sửa
region = "shopee.co.id"
 
# Danh sách region được hỗ trợ
# ["shopee.co.id", "shopee.vn", "shopee.co.th", "shopee.ph", "shopee.com.my", "shopee.sg", "shopee.com.co", "shopee.cl", "shopee.com.mx", "shopee.com.br", "shopee.tw"] 
 
url = f"https://{region}/api/v4/search/search_items?limit={limit}&newest=0&by=sales&keyword={keyword}&order={order}&page_type={page_type}&scenario=PAGE_OTHERS&version=2"
print(url)

Truy xuất kết quả tác vụ thông qua TaskId

import requests
 
API_KEY = ""
host = "api.scrapeless.com"
task_id = ""
 
url = f"https://{host}/api/v1/scraper/result/{task_id}"
 
headers = {
   'x-api-token': f'{API_KEY}'
}
 
response = requests.request("GET", url, headers=headers)
 
print(response.text)