处理客户端转换页面
Use browser-backed retrieval when required content appears only after page JavaScript has executed.
Review request controls浏览器界限更清晰
Use browser-backed retrieval when required content appears only after page JavaScript has executed.
Review request controlsWait for a lifecycle event, delay, selector, or documented instruction step instead of parsing whatever happens to arrive first.
See the request workflowReturn rendered HTML, a JSON response, a JSON DOM, selected fields, or a screenshot for the downstream task.
Compare output options要求解剖学
开始使用target的URL,然后只添加需要复制页面状态的文件控制. 参数指南 浏览器 API.
定义托管浏览器如何访问和框架页面.
api_keyurlmethodbodycountrytimeoutdevicewindow_widthwindow_heightblock_resources告诉请求页面准备好时以及接下来要做什么.
wait_untilwait_forwait_for_cssjs_instructionsauto_solveclickscrollTotyped_valueselectsubmitclick_and_navigate选择浏览器支持的请求应该返回什么.
screenshotscreenshot_optionsextract_rulesjson_responsejson_dom偏好可观察的选择器或生命周期状态,而不是任意的延迟,保持行动序列短暂,并根据您自己的业务要求验证返回的内容.
请求工作流程
Provide the URL, method, country, device, viewport, and timeout required for the test case.
Choose domcontentloaded, load, networkidle0, networkidle2, a delay, or a selector.
Apply an ordered js_instructions sequence when the page needs clicks, scrolling, values, selections, or navigation.
Receive the requested format or explicit error, then validate content before it enters the downstream system.
选择器或页面生命周期条件与您需要的内容相关.
只有需要采取的行动才能达到稳定的,可重复的状态.
浏览器执行仍然可能失败,暂停或返回需要商业验证的内容.
产出合同
捕获一次的页面,然后选择一个符合现有解析器,验证步骤,证据记录或媒体工作流的记录输出.
返回染页面体,为您的团队运行的解析或档案过程.
text/html包装机体以文件要求和target-回应文本进行检查.
json_response接收页面文档作为下游通行的JSON DOM表示.
json_dom执行客户定义的CSS或XPath规则,然后返回所选的内容.
extract_rules捕获完整页面或选定的元素,并作为Base64接收图像.
screenshot开发人员集成
通过服务器调用REST端点,将API密钥排除在客户端代码,URL编码请求参数之外,设置有限的时间限期,并故意处理未成功的响应.
https://api.webscrapingapi.com/v1WSA_API_KEY 在服务器环境中wait_for_css=mainjs_instructions: "${WSA_API_KEY:?Set WSA_API_KEY}"
ACTIONS='[{"action":"scrollTo","selector":"main","timeout":1000,"block":"start"}]'
curl --get --fail-with-body --max-time 120 \
"https://api.webscrapingapi.com/v1" \
--data-urlencode "api_key=$WSA_API_KEY" \
--data-urlencode "url=https://example.com/app" \
--data-urlencode "wait_for_css=main" \
--data-urlencode "js_instructions=$ACTIONS" \
--data-urlencode "json_response=1"import json
import os
import requests
api_key = os.getenv("WSA_API_KEY")
if not api_key:
raise RuntimeError("Set WSA_API_KEY")
response = requests.get(
"https://api.webscrapingapi.com/v1",
params={
"api_key": api_key,
"url": "https://example.com/app",
"wait_for_css": "main",
"js_instructions": json.dumps([{
"action": "scrollTo", "selector": "main",
"timeout": 1000, "block": "start"
}]),
"json_response": 1,
},
timeout=120,
)
response.raise_for_status()
print(response.json())const apiKey = process.env.WSA_API_KEY;
if (!apiKey) throw new Error("Set WSA_API_KEY");
const params = new URLSearchParams({
api_key: apiKey,
url: "https://example.com/app",
wait_for_css: "main",
js_instructions: JSON.stringify([{
action: "scrollTo", selector: "main",
timeout: 1000, block: "start"
}]),
json_response: "1",
});
const response = await fetch(
"https://api.webscrapingapi.com/v1?" + params,
{ signal: AbortSignal.timeout(120_000) }
);
if (!response.ok) throw new Error("API status " + response.status);
console.log(await response.json());<?php
$apiKey = getenv("WSA_API_KEY");
if (!$apiKey) throw new RuntimeException("Set WSA_API_KEY");
$actions = json_encode([[
"action" => "scrollTo", "selector" => "main",
"timeout" => 1000, "block" => "start",
]], JSON_THROW_ON_ERROR);
$query = http_build_query([
"api_key" => $apiKey,
"url" => "https://example.com/app",
"wait_for_css" => "main",
"js_instructions" => $actions,
"json_response" => 1,
]);
$client = curl_init("https://api.webscrapingapi.com/v1?" . $query);
curl_setopt_array($client, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($client);
$status = curl_getinfo($client, CURLINFO_RESPONSE_CODE);
$error = curl_error($client);
curl_close($client);
if ($body === false) throw new RuntimeException($error);
if ($status >= 400) throw new RuntimeException("API status " . $status);
echo $body;package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
)
func main() {
apiKey := os.Getenv("WSA_API_KEY")
if apiKey == "" { panic("Set WSA_API_KEY") }
params := url.Values{}
params.Add("api_key", apiKey)
params.Add("url", "https://example.com/app")
params.Add("wait_for_css", "main")
params.Add("js_instructions", "[{\"action\":\"scrollTo\",\"selector\":\"main\",\"timeout\":1000,\"block\":\"start\"}]")
params.Add("json_response", "1")
client := &http.Client{Timeout: 120 * time.Second}
response, err := client.Get(
"https://api.webscrapingapi.com/v1?" + params.Encode(),
)
if err != nil { panic(err) }
defer response.Body.Close()
if response.StatusCode >= 400 {
panic(fmt.Sprintf("API status %d", response.StatusCode))
}
body, err := io.ReadAll(response.Body)
if err != nil { panic(err) }
fmt.Println(string(body))
}import java.net.URI;
import java.net.URLEncoder;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
public final class BrowserApiExample {
public static void main(String[] args) throws Exception {
var apiKey = System.getenv("WSA_API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalStateException("Set WSA_API_KEY");
}
var actions = "[{\"action\":\"scrollTo\",\"selector\":\"main\"," +
"\"timeout\":1000,\"block\":\"start\"}]";
var query = "api_key=" + URLEncoder.encode(apiKey, StandardCharsets.UTF_8)
+ "&url=" + URLEncoder.encode("https://example.com/app", StandardCharsets.UTF_8)
+ "&wait_for_css=main"
+ "&js_instructions=" + URLEncoder.encode(actions, StandardCharsets.UTF_8)
+ "&json_response=1";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.webscrapingapi.com/v1?" + query))
.timeout(Duration.ofSeconds(120)).GET().build();
var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 400) {
throw new RuntimeException("API status " + response.statusCode());
}
System.out.println(response.body());
}
}
using System.Net.Http;
var apiKey = Environment.GetEnvironmentVariable("WSA_API_KEY");
if (string.IsNullOrWhiteSpace(apiKey))
throw new InvalidOperationException("Set WSA_API_KEY");
var actions = "[{\"action\":\"scrollTo\",\"selector\":\"main\"," +
"\"timeout\":1000,\"block\":\"start\"}]";
var requestUrl = "https://api.webscrapingapi.com/v1?api_key="
+ Uri.EscapeDataString(apiKey)
+ "&url=" + Uri.EscapeDataString("https://example.com/app")
+ "&wait_for_css=main"
+ "&js_instructions=" + Uri.EscapeDataString(actions)
+ "&json_response=1";
using var client = new HttpClient {
Timeout = TimeSpan.FromSeconds(120)
};
var response = await client.GetAsync(requestUrl);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());require "json"
require "net/http"
require "uri"
api_key = ENV["WSA_API_KEY"]
raise "Set WSA_API_KEY" if api_key.nil? || api_key.empty?
uri = URI("https://api.webscrapingapi.com/v1")
uri.query = URI.encode_www_form(
api_key: api_key,
url: "https://example.com/app",
wait_for_css: "main",
js_instructions: [{
action: "scrollTo", selector: "main",
timeout: 1000, block: "start"
}].to_json,
json_response: 1
)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = 10
http.read_timeout = 120
response = http.get(uri.request_uri)
raise "API status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
puts response.body运营所有权
WebScrapingAPI
您的团队
Use Browser API only for eligible public pages. Review source terms, applicable requirements, and the 服务协议, then apply appropriate access, retention, and data-use policies.
使用情况
产品选择
您的团队运行HTTP客户端,浏览器或解析器,重新尝试政策,验证和存储.
发送一个管理页面请求的URL,可选的染和记录响应格式.
在一个服务器端 REST 请求中定义准备,支持的操作,背景和输出.
计划一个有限的集合,当工作单位覆盖相关的符合条件的页面而不是一个浏览器请求.
定义源,方案,随机,质量和目的地,而WebScrapingAPI运行复发程序.
价格指导
开始一个代表性动态页面,然后验证最小的文本,准备,行动和输出组合,
FAQ
浏览器 API是一个服务器端 REST请求,在托管的浏览器中加载一个符合条件的公开网页,应用记录的等待和操作,并返回选择的响应到您的应用程序.
文件输出选项包括原始HTML,JSON包裹,JSON DOM表示,客户定义的提取字段,以及回应内部作为base64返回的截图.
文件编写的JavaScript指令包括点击,点击和导航,滚动,输入值,值分配,选择,提交,关注和等待.构建和测试达到您需要的状态的最短序列.
使用文档中列出的页面生命周期值、延迟时间或 CSS 选择器。您可以根据目标页面的行为,组合 wait_until、wait_for、wait_for_css 和指令级等待。
是的. 文件控制包括桌面,移动或平板电脑设备的背景;窗口宽度和高度;以及支持国家级请求背景.
号码 浏览器 API 使用请求响应 REST 接口. 应用程序通过请求参数声明支持的等待,操作,文本和输出,然后收到选择的响应或API错误.
WebScrapingAPI运行托管的浏览器执行并返回所需的输出.您的团队拥有 target的资格,交互说明,选择器,提取方案,内容验证和源更改维护.