参数说明
瞭解 Thordata 的 Universal Scraping API - 抓取參數。
Token(必填):
該參數定義了爬取時使用的 API 令牌。對於您的成功爬取起到決定性作用。
token
Token
爬取時驗證的 API 令牌
URL(必填):
該參數定義了爬取的目的網站連結,預設值為 google.com。您也可以更改為其他搜尋引擎連結。
url
URL
爬取的目的網站的連結
示例請求:
帶有token:Token ,url:https://www.google.com 的參數示例
curl -X POST https://universalapi.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True"js_render ,JS渲染(非必填)
JS渲染能夠處理動態載入的內容和單頁應用(SPA),支援更互動複雜的頁面和渲染需求,建議您開啟。
js_render=True
js_render=False
示例請求:
帶有 js_render:True 的參數示例
curl -X POST https://universalapi.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True"type ,輸出格式(非必填)
該參數定義了抓取結果的輸出格式。可選擇HTML和PNG格式,預設為HTML。
format=HTML
format=PNG
示例請求:
帶有 type:png 的參數示例
curl -X POST https://universalapi.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=png" -d "js_render=True"header ,Header(非必填)
啟用後,輸出結果中會包含請求頭的信息。
示例請求:
帶有 header:Ture 的參數示例
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=True" \
-d "header=True"block_resources,阻止(非必填)
該參數可限制不必要的資源抓取,從而加快抓取速度。
block_resources=圖片
block_resources=Javascript腳本
示例請求:
帶有 block_resources:script 的參數示例
curl -X POST https://universalapi.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True" -d "block_resources=script"country,代理(非必填)
該參數定義了爬取時的代理使用哪個國家/地區,預設值無代理國家。
country=隨機
country=任意國家代碼
示例請求:
帶有country:al 的參數示例
curl -X POST https://universalapi.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True" -d "country=al"clean_content,清除(非必填)
此參數用於從返回結果中刪除 JS 和 CSS 內容。
示例请求:
帶有 clean_content: JS,CSS 的參數示例
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=True" \
-d "clean_content=js,css" \
-d "header=False"wait,等待(毫秒)(非必填)
該參數旨在等待頁面加載內容所需的毫秒數。(適用於速度較慢的網站)
示例请求:
带有帶有 wait:1000 的參數示例
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=True" \
-d "wait=10000"wait_for,等待选择器(非必填)
等待 CSS 選擇器在 DOM 中載入,若同時使用 wait_for 和 wait,則以 wait_for 為優先(覆蓋固定時間)。指定元素最長等待 30 秒,超時後會自動返回網站內容。
示例请求:
带有帶有 wait_for:.content 的參數示例
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=True" \
-d "wait=10000" \
-d "wait_for=.content"headers,自定義headers(非必填)
傳遞自定義headers到您正在抓取的網站。(例如:{"name":"value"})
示例请求:
如果您想發送 User-Agent 和 Content-Type,則應如下所示:
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=token" \
-d 'headers=[{"name":"name1","value":"value1"}]' \
-d 'cookies=[{"name":"name2","value":"value2"}]'cookies,Cookies(非必填)
將自定義 cookie 傳遞給目標網站,多個 cookies 時請用英文分號 ; 分隔。
Cookie 是網站透過瀏覽器存儲在用戶設備上的小塊數據。它們允許網站保留用戶資訊,例如登入狀態、偏好設定或追蹤詳情,從而改善並個人化瀏覽體驗。
發出請求時,您可以通過兩種方式添加 cookie:
在
headers參數中:以以下格式將其作為Cookie標頭的一部分發送:
(例如:headers:{"name":"Cookie","value":"cookie_name_1=cookie_value_1"})
使用專用的
cookies參數:直接以以下格式傳遞: (例如:{""Cookie":"cookie_name_1=cookie_value_1"})
示例请求:
使用專用的 cookies 參數:直接以以下格式傳遞:
cookie_name_1=cookie_value_1; cookie_name_2=cookie_value_2
curl -X POST https://universalapi.thordata.com/request \
-H "Authorization: Bearer token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "url=https://www.google.com" \
-d "type=html" \
-d "js_render=token" \
-d 'headers=[{"name":"name1","value":"value1"}]' \
-d 'cookies=[{"name":"name2","value":"value2"}]'Last updated
Was this helpful?