API Overview
A-Parser supports management through an API, which allows integrating the scraper into complex systems (for example, SaaS), using A-Parser's capabilities from other programs and scripts.
The API is implemented based on the HTTP
protocol and JSON
data serialization and can be used from any programming language.
- curl
- NodeJS
- Perl
- Python
- PHP
curl http://127.0.0.1:9091/API \
-H 'Content-Type: application/json' \
-d '{"password":"123","action":"ping"}'
ะ ะตะทัะปััะฐั:
{"success":1,"data":"pong"}
const AParserClient = require('a-parser-client');
const AParser = new AParserClient('http://127.0.0.1:9091/API', '123');
AParser.ping()
.then(reply => console.log(reply.data))
.catch(err => console.log(err));
use AParser;
use Data::Dumper;
my $parser = AParser->new('http://127.0.0.1:9091/API', '123');
warn "Ping result:\n", Dumper $parser->ping();
from a_parser import AParser
aparser = AParser('http://127.0.0.1:9091/API', '123')
print(aparser.ping())
require_once 'aparser-api-php-client.php';
$aparser = new Aparser('http://127.0.0.1:9091/API', '123');
echo $aparser->ping();
Usage examplesโ
- Calling and processing single or batch requests to any of the scrapers, for example:
- Getting a list of links from Google by query
- Translating text through Google Translate/Yandex Translate/DeepL
- Getting domain parameters such as registration date, Alexa rank, and many others
- Queuing tasks and getting results
- Managing the task queue and monitoring task status
- Automating the work of the scraper farm
Ready-made clientsโ
There are ready-made clients for A-Parser that simplify working with the API:
NodeJSโ
Perlโ
PHPโ
Pythonโ
Request formationโ
Interaction with A-Parser occurs over the HTTP protocol with JSON serialization of the request and response. To make a request to the API, you must make a POST request to the address:
http://IP-ัะตัะฒะตัะฐ:9091/API
The following headers must be passed:
content-length
content-type: application/json
The JSON-serialized structure is used as the request body (post body):
{
"password": "pass",
"action": "oneRequest",
"data": {
...
}
}
Where:
password
- password for A-Parseraction
- the called API methoddata
- request parameters, specific to each type of request, the full list and description here
The response in general looks like this:
{
"success": 1,
"data": "..."
}
Where:
success
- success of the API request, can take the value 1 or 0data
- response to the called method, can be a scalar or an object, depending on the type of request
PHP code exampleโ
We recommend using the PHP client, this code is provided for informational purposes only:
$aparser = 'http://127.0.0.1:9091/API';
$request = json_encode(array(
'action' => 'oneRequest',
'data' => array (
'parser' => 'SE::Google',
'preset' => 'Pages Count use Proxy',
'query' => 'test'
),
'password' => 'pass'
));
$ch = curl_init($aparser);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($request)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain; charset=UTF-8'));
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, true);
echo $response['data']['resultString'];
Perl code exampleโ
We recommend using the Perl client, this code is provided for informational purposes only:
use LWP;
use JSON::XS;
my $aparser = 'http://127.0.0.1:9091/API';
my $request = encode_json {
'action' => 'oneRequest',
'data' => {
'parser' => 'SE::Google',
'preset' => 'Pages Count use Proxy',
'query' => 'test'
},
'password' => 'pass'
};
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
$aparser,
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Length' => length $request,
'Content' => $request
);
if($response->is_success) {
my $json = decode_json $response->content();
print $json->{'data'}->{'resultString'};
}
else {
warn 'Response fail: ', $response->status_line();
};
Getting an API request in the interfaceโ
To get the full API request in the Task Editor, there is a function Get API request. With its help, you can get the full JSON for use in the addTask(Add task) method
Redis APIโ
Redis API is an alternative way to integrate A-Parser through the Redis server, providing greater flexibility and performance in some scenarios, read more in the Redis API section