Shopeeウェブサイトデータスクレイピング
パラメータ説明
パラメータ | 型 | 値 | 説明 |
---|---|---|---|
actor | string | scraper.shopee | 固定 |
input.action | string | shopee.product | 3つのタイプをサポート 1. shopee.product 商品詳細データ取得 2. shopee.search キーワード検索データ 3. shopee.live ライブ関連データ |
input.url | string | URLリンク | 4種類のURLリンクをサポート 1. 商品詳細ページのURLリンク 2. 商品詳細ページのAPIリンク (/api/v4/pdp/get_pc) 3. 商品検索のAPIリンク (/api/v4/search/search_items) 4. ライブ放送のAPIリンク (/api/v1/session/{sessionId} /more_items) |
商品詳細データ
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)
商品検索データ
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)
ライブデータ
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)
APIリンクの構築方法
商品詳細ページAPI
# APIは3つの部分に分割できます
# 1. region
# 2. item_id
# 3. shop_id
# サポートされているリージョンリスト
# ["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
limit = 20 # 10 20 30 40
order = "desc"
page_type = "search"
keyword = "keyword" # 編集してください
region = "shopee.co.id"
# サポートされているリージョンリスト
# ["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)
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)