等待CSS
将 CSS 选择器传递给 wait_for_css,API 会在返回页面之前最多等待 10 秒,等待该元素出现。如果选择器始终没有出现,请求会失败且不会计费。
Endpoint
Section titled “Endpoint” GET https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=<TARGET_URL>&wait_for_css=<CSS_SELECTOR>&render_js=1
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
api_key | string | yes | 您的 Web Scraping API 密钥 |
url | string | yes | 要抓取的目标 URL |
wait_for_css | string | yes | 要等待的 CSS 选择器。 |
render_js | integer | yes | 必须为 1。 |
timeout | integer | no | 最长等待时间(毫秒)。默认值为 10000。 |
Example request
Section titled “Example request”curl "https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=https://example.com&wait_for_css=.firstHeading&render_js=1"import requests
r = requests.get("https://scrape.shifter.io/v1", params={ "api_key": "YOUR_API_KEY", "url": "https://example.com", "wait_for_css": ".firstHeading", "render_js": 1,})print(r.text)import fetch from 'node-fetch';
const url = 'https://scrape.shifter.io/v1?' + new URLSearchParams({ api_key: 'YOUR_API_KEY', url: 'https://example.com', wait_for_css: '.firstHeading', render_js: '1',});const res = await fetch(url);console.log(await res.text());Example response
Section titled “Example response”<!doctype html><html><head> <title>Example Domain</title></head><body><div> <h1>Example Domain</h1> <p>This domain is for use in illustrative examples in documents.</p></div></body></html>