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>