Skip to content
登录 注册

强制超时

有些页面在主要内容准备就绪后,仍有少数 DOM 节点会持续加载很长时间。使用 timeout 参数来限制总渲染时间。计时结束时,API 会返回当前已获取到的 HTML,若没有收集到任何可用内容,则返回 422 及相应的错误说明。

GET https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=<TARGET_URL>&render_js=1&timeout=<MILLISECONDS>
ParameterTypeRequiredDescription
api_keystringyes您的 Web Scraping API 密钥
urlstringyes要抓取的目标 URL
timeoutintegerno引擎允许花费的最长渲染时间,单位为毫秒。最大值为 60000
render_jsintegerno设置为 1 以渲染 JavaScript。
Terminal window
curl "https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=https%3A%2F%2Fhttpbin.org%2Fget&render_js=1&timeout=200"
{
"status": "Failure",
"status_code": 422,
"created_at": "2022-04-26T11:57:23.242Z",
"processed_at": "2022-04-26T11:57:23.739Z",
"time_taken": {
"total": 0.701,
"scraping": 0.202,
"setup_worker": 0.403
},
"error": "The target page took more than 0.2 seconds to load, the website might be down. Retry the request or increase the value of 'timeout' parameter.",
"page_content": null
}