How to Use ScrapingRobot API

如何使用 Scraping Robot API?购买前学习手册

想购买 Scraping Robot API 用于网络搜索?在此之前,你必须知道如何使用它。本文将为你提供详细指导。

搜索机器人应用程序接口

基本用法

本页将介绍 Scraping Robot 的基本功能

Scraping Robot API 只提供一个 API 端点。只需发送 http 请求到 https://api.scrapingrobot.com 使用作为查询参数传递的 API 密钥,获取所需的数据。

所有任务参数都以 JSON 对象的形式在 POST 主体中传递。

POST 示例代码

https://api.scrapingrobot.com?token=<YOUR_SR_TOKEN>

代码示例

{  
  "url": "https://www.scrapingrobot.com/",  
  "模块": "HtmlChromeScraper" 
}

认证

向 Scraping Robot API 提出的每个请求都应包含一个访问令牌。如果用户没有提供令牌或令牌无效,Scraping Robot 将以状态 401(未授权)作出响应。

令牌可以通过两种方式传递:

  • 作为查询参数:
    • token=
  • 在授权标头(承载认证)中:
    • 授权:承载者

请注意: 要获得 Scraping Robot API 访问令牌,您必须在以下网址注册账户 https://dashboard.scrapingrobot.com/sign-up.


错误处理

授权参数缺失

如果你忘记将 Scraping Robot 面板上的 API 密钥作为 "令牌 "路径参数包含在 API 调用中,我们会在屏幕右侧显示错误信息。

授权参数缺失

{
   "状态": "失败",
   "日期": "Thu, 01 Mar 2020 10:00:00 GMT",
   "错误": "未找到令牌查询参数"
}

要纠正这一错误,请在 API 调用中将您的 Scraping Robot 面板中的 API 密钥作为 "令牌 "路径参数,这样您就有权向我们的系统提出请求。


授权参数无效

如果您在 API 调用中将无效的 API 密钥作为 "令牌 "路径参数,我们将在屏幕右侧显示错误信息。

授权参数无效

{
   "状态": "失败",
   "日期": "Thu, 01 Mar 2020 10:00:00 GMT",
   "错误": "客户端令牌无效"
}

要纠正这一错误,请在 API 调用中将您的 Scraping Robot 面板中的 API 密钥作为 "令牌 "路径参数,这样您就有权向我们的系统提出请求。


学分不足

如果您的账户中没有足够的点数来执行您请求的刮擦任务,我们将在屏幕右侧显示错误信息。

学分不足

{
  "状态":"FAIL"、
  "date":"Thu, 01 Mar 2020 10:00:00 GMT"、
  "错误":"您没有足够的点数
}

要纠正此错误,请通过 Scraping Robot 控制面板或 联系我们的支持团队 将积分添加到您的账户。


请求体不是有效的 JSON

如果您发送的请求没有有效的 JSON,我们会在屏幕右侧显示错误信息。

无效 JSON 包括任何非 JSON 格式和不具备 JSON 结构的内容。这与接下来解释的 "无效请求正文 "错误不同。

请求体不是有效的 JSON

{
  "状态":"FAIL"、
  "date": "Thu, 01 Mar 2020 10:00:00 GMT"、
  "error":"Request-body is not a valid JSON" (请求体不是有效的 JSON
}

要纠正此错误,请修复请求正文中的 JSON 并再次尝试请求。您可以在网上找到 JSON 验证器,帮助您正确格式化 JSON。


无效请求体

如果您发送了 JSON 正文,但正文参数不正确或顺序不对,我们会在屏幕右侧显示错误信息。

无效请求体

{
  "状态":"FAIL"、
  "date": "Thu, 01 Mar 2020 10:00:00 GMT"、
  "error":"无效 json 格式:..."
}

要纠正此错误,请查看您发送的请求的 API 文档,以确保所有参数正确无误。如果您无法自行解决该问题,请 联系我们的支持团队 寻求帮助,我们很乐意提供帮助!


服务超载

如果在您提出请求时我们的服务已超负荷,我们将在屏幕右侧显示错误信息。

服务超载

{
  "状态":"FAIL"、
  "date": "Thu, 01 Mar 2020 10:00:00 GMT"、
  "错误":"服务超载。稍后再试"。
}

要纠正这一错误,请 联系我们的支持团队 了解最新情况。


页面加载失败

如果 Scraping Robot 无法加载您要搜刮的页面,我们会在屏幕右侧显示错误信息。

页面加载失败

{
  "状态":"FAIL"、
  "date": "Thu, 01 Mar 2020 10:00:00 GMT"、
  "错误":"请稍后再重试此任务"
}

要纠正这一错误,请 联系我们的支持团队 寻求帮助。


内部错误

如果我们的系统出现问题,我们会在屏幕右侧显示错误信息。

内部错误

{
  "错误":"内部服务器错误"、
  "date":"Thu, 01 Mar 2020 10:00:00 GMT"、
  "status":"FAIL" (失败)
}

要纠正这一错误,请 联系我们的支持团队 寻求帮助。


荣誉

获取信贷余额

获取

cURL节点PHPPythonJavaScriptC++

要求

curl --request GET\
--url https://api.scrapingrobot.com/balance \
--header'Accept:application/json'(接受:应用程序/json

要求

const sdk = require('api')('@staging-docs-scrapingrobot/v1.0#1b382ykufox5uf');

sdk.get('/balance')
.then(res => console.log(res))
.catch(err => console.error(err));

要求

 
request('GET', 'https://api.scrapingrobot.com/balance', [
标题' => [
'Accept' => 'application/json'、
],
]);

echo $response->getBody();

要求

进口请求

url = "https://api.scrapingrobot.com/balance"

headers = {"Accept":"application/json"}

response = requests.request("GET", url, headers=headers)

print(response.text)

要求

const options = {method: 'GET', headers:{Accept: 'application/json'}};

fetch('https://api.scrapingrobot.com/balance', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

要求

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd,CURLOPT_URL, "https://api.scrapingrobot.com/balance");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
[/su_tab]

获取信贷使用统计

该终端将显示指定时间段内的信用额度使用情况。

cURL节点PHPPython选项卡标题C++

要求

curl --request GET\
--url 'https://api.scrapingrobot.com/balance?token=' \
--header'Accept:application/json'(接受:应用程序/json

要求

const fetch = require('node-fetch');
const url = 'https://api.scrapingrobot.com/balance?token=';
const options = {method: 'GET', headers:{Accept: 'application/json'}};
fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));

要求

request('GET', 'https://api.scrapingrobot.com/balance?token=', [
标题' => [
'Accept' => 'application/json'、
],
]);

echo $response->getBody(); 

要求

进口请求

url = "https://api.scrapingrobot.com/balance?token="

headers = {"Accept":"application/json"}

response = requests.request("GET", url, headers=headers)

print(response.text)

要求

const options = {method: 'GET', headers:{Accept: 'application/json'}};

fetch('https://api.scrapingrobot.com/balance?token=', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

要求

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.scrapingrobot.com/balance?token=");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
[/su_tab]

Html API

使用 POST 请求创建任务

/

创建刮擦任务
cURL节点PHP PythonJavaScriptC++

要求

curl --request GET\
--url 'https://api.scrapingrobot.com/stats?token=&type=daily'\
--header'Accept:application/json'(接受:应用程序/json

要求

const fetch = require('node-fetch');

const url = 'https://api.scrapingrobot.com/stats?token=&type=daily';
const options = {method: 'GET', headers:{Accept: 'application/json'}};

fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));

要求

request('GET', 'https://api.scrapingrobot.com/stats?token=&type=daily', [
标题' => [
Accept' => 'application/json'、
],
]);

echo $response->getBody();

要求

进口请求

url = "https://api.scrapingrobot.com/stats?token=&type=daily"

headers = {"Accept":"application/json"}

response = requests.request("GET", url, headers=headers)

print(response.text)

要求

const options = {method: 'GET', headers:{Accept: 'application/json'}};

fetch('https://api.scrapingrobot.com/stats?token=&type=daily', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

要求

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.scrapingrobot.com/stats?token=&type=daily");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
[/su_tab]

使用 GET-request 创建任务

/

创建刮擦任务

cURL节点PHPPythonJavaScriptC++

要求

curl --request POST \
--url 'https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true&contentType=text%2Fplain' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json'

要求

const sdk = require('api')('@staging-docs-scrapingrobot/v1.0#1b382ykufox5uf');

sdk.server('https:/api.scrapingrobot.com/');
sdk.post('', {
responseType: 'json',
waitUntil: 'load',
noScripts: 'false',
noImages: 'true',
noFonts: 'true',
noCss: 'true',
contentType: 'text%2Fplain'
})
.then(res => console.log(res))
.catch(err => console.error(err));

要求

<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true&contentType=text%2Fplain', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
]);

echo $response->getBody();

要求

import requests

url = "https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true&contentType=text%2Fplain"

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

response = requests.request("POST", url, headers=headers)

print(response.text)

要求

const options = {
method: 'POST',
headers: {Accept: 'application/json', 'Content-Type': 'application/json'}
};

fetch('https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true&contentType=text%2Fplain', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

要求

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true&contentType=text%2Fplain");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
[/su_tab]

获取当前积分余额

/平衡

获取

获取当前积分余额

cURL节点PHP PythonJavaScriptC++

要求

curl --request GET\
--url https://api.scrapingrobot.com/ \
--header'Accept:application/json'(接受:应用程序/json

要求

const sdk = require('api')('@staging-docs-scrapingrobot/v1.0#1b382ykufox5uf');

sdk.server('https:/api.scrapingrobot.com/');
sdk.get('', {
responseType:'json'、
waitUntil:load'、
noScripts:false'、
noImages:true
noFonts: 'true'、
noCss: 'true
})
.then(res => console.log(res))
.catch(err => console.error(err));

要求

request('GET', 'https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true', [
标题' => [
'Accept' => 'application/json'、
],
]);

echo $response->getBody();

要求

进口请求

url = "https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true"

headers = {"Accept":"application/json"}

response = requests.request("GET", url, headers=headers)

print(response.text)

要求

const options = {method: 'GET', headers:{Accept: 'application/json'}};

fetch('https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

要求

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.scrapingrobot.com/?responseType=json&waitUntil=load&noScripts=false&noImages=true&noFonts=true&noCss=true");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
[/su_tab]

参考资料


免责声明:这部分内容主要来自商家。如果商家不希望在我的网站上显示,请 联系我们 删除您的内容。

最后更新于 5 月 15, 2022

您推荐代理服务吗?

点击奖杯即可颁奖!

平均评分 0 /5.计票: 0

目前没有投票!成为第一个给本帖评分的人。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

滚动到顶部