参数说明
了解 Thordata 的 通用抓取 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"
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
,等待(毫秒)(非必填)
等待页面在指定时间内加载内容(以毫秒为单位)。最大值:100,000 毫秒(100 秒)
示例请求:
带有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: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" \
-d "wait_for=.content"
headers
,自定义headers(非必填)
向目标网站传递自定义请求头,多个 headers 时请用英文逗号‘,’分隔; HTTP标头是键值对,以冒号 (:) 分隔。发送的参数应采用 JSON 格式。
示例请求:
如果您想发送 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
允许网站保留用户信息,例如登录状态、偏好设置或追踪详情,从而改善和个性化浏览体验。
发出请求时,您可以通过两种方式添加 cookie
:
在 headers
参数中:(例如:{""Cookie
":"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?