Skip to main content

A-Parser Control Module via API for Python

Compatibility

The module is compatible with Python version 2.7.* and >=3.8

Installation

pip install a-parser

Usage

Connecting the module and checking its operation using the ping method.

from a_parser import AParser
aparser = AParser('http://127.0.0.1:9091/API', 'password')
print(aparser.ping())

Result:

{ 'success': 1, 'data': 'pong' }

Adding a task through addTask. The waitForTask() method is discussed in more detail below in the Methods section.

taskId = aparser.addTask(
[['SE::Google', 'default',
{
'type': 'override',
'id': 'formatresult',
'value': '$serp.format("$anchor\\n")'
}, {
'type': 'override',
'id': 'pagecount',
'value': 1
}, {
'type': 'override',
'id': 'useproxy',
'value': False
}
]],
'default',
'text',
'diamond',
resultsFormat= '$p1.preset',
uniqueQueries= False,
queryFormat= ['$query'],
resultsUnique= 'no',
resultsSaveTo= 'file',
resultsFileName= '$datefile.format().txt',
doLog= 'no',
keepUnique= 'No',
moreOptions= False,
resultsPrepend= '',
resultsAppend= '',
configOverrides= [],
queryBuilders= []
)['data']

aparser.waitForTask(taskId)
print(aparser.getTaskResultsFile(taskId))

Result:

{'success': 1, 'data': 'http://127.0.0.1:9091/downloadResults?fileName=Jul-29_17-33-37.txt&token=utmxidbc'}

Adding a task through oneRequest.

print(aparser.oneRequest('SE::Yahoo::Suggest', 'default', 'spider'))

Result:

{
"success" : 1,
"data" : {
"logs" : [
[
0,
1596033005,
"Parser SE::Yahoo::Suggest::0 parse query spider"
],
[
0,
1596033005,
"Use proxy http://51.255.55.144:28466"
],
[
0,
1596033006,
"GET(1): http://sugg.search.yahoo.com/gossip-us-fp/?nresults=10&output=yjson&version=&command=spider - 200 OK (0.3 KB)"
],
[
3,
1596033006,
1
],
[
0,
1596033006,
"Thread complete work"
]
],
"resultString" : "spider - spider:\nspider solitaire\nspiderman\nspider bites\nspider bite pictures\nspider solitaire two suits\nspider plant\nspider-man\nspider solitaire free\nspider bites pictures and symptoms\nspider monkey\n"
}
}

Methods

The module implements all the methods available for use in the A-Parser API. You can find the list of them here

waitForTask

The waitForTask() method allows you to wait for the completion of a task. As arguments, you should specify the task id and the interval in seconds (optionally). By default, the interval for checking the task status is set to 5 seconds. As soon as the task status equals completed, the method will return this value