JavaScript 指令
将经过 URL 编码的浏览器操作 JSON 数组传递给 js_instructions。API 会按顺序执行这些操作,然后返回最终的 HTML。这对分页列表、无限滚动和表单驱动的流程非常有用。
Endpoint
Section titled “Endpoint” GET https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=<TARGET_URL>&render_js=1&js_instructions=<URL_ENCODED_JSON>
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
api_key | string | yes | 您的 Web Scraping API 密钥 |
url | string | yes | 要抓取的目标 URL |
js_instructions | string | yes | 经过 URL 编码的操作对象 JSON 数组。 |
render_js | integer | yes | 必须为 1。 |
Action object
Section titled “Action object”| Field | Type | Description |
|---|---|---|
action | string | 取值为 click、scrollTo、focus、value 或 submit(仅表单)之一。 |
selector | string | 目标元素的 CSS 选择器。 |
timeout | integer | 此操作完成后等待的毫秒数。 |
Example request
Section titled “Example request”[{"action":"scrollTo","selector":"div.navFooterBackToTop","timeout":5000,"block":"start"}]curl "https://scrape.shifter.io/v1?api_key=YOUR_API_KEY&url=https://example.com&render_js=1&js_instructions=%5B%7B%22action%22%3A%22scrollTo%22%2C%22selector%22%3A%22div.navFooterBackToTop%22%2C%22timeout%22%3A%205000%2C%20%22block%22%3A%20%22start%22%7D%5D"import jsonimport requests
instructions = [{ "action": "scrollTo", "selector": "div.navFooterBackToTop", "timeout": 5000, "block": "start",}]r = requests.get("https://scrape.shifter.io/v1", params={ "api_key": "YOUR_API_KEY", "url": "https://example.com", "render_js": 1, "js_instructions": json.dumps(instructions),})print(r.text)import fetch from 'node-fetch';
const instructions = [{ action: 'scrollTo', selector: 'div.navFooterBackToTop', timeout: 5000, block: 'start',}];const url = 'https://scrape.shifter.io/v1?' + new URLSearchParams({ api_key: 'YOUR_API_KEY', url: 'https://example.com', render_js: '1', js_instructions: JSON.stringify(instructions),});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>