How to use Yandex search API

My experience of Yandex Cloud Search API usage.

ya search engine API with seo and Web design|lower


YANDEX API

1. Documentation is available at cloud.yandex.ru/ru/services/search-api

2. You get results as XML

3. Enter to console.cloud.yandex.com

4. activate billing account

5. I need service account to use Search API and API key

5.1 Create service acc in console.cloud.yandex.ru/folders button at the top of the screen. Assign editor and search-api.executor role.

5.2 Create API

5.3. I get error when click save button: Cannot authorize by IAM token, cause: PERMISSION_DENIED: The cloud 'xxxxx' is inactive // I have to wait while my billing account will be activated.

6. To test $ curl 'https://yandex.ru/search/xml?folderid=<folder_ID>&apikey=<API_key_value>&query=<search_query_text>'

6.1. I get only 10 results with my get request 

req = requests.get( "https://www.yandex.ru/search/xml?folderid=b1g7qugqe2sebo6hesa8"+

"&apikey=МОЙАПИКЛЮЧ&query=проект"+

"&groupby=attr%253Dd.mode%253Ddeep.groups-on-page%253D100.docs-in-group%253D1" ) // Instead of %253D use %3D e.g =

6.1.1. Try POST request.

requests.post(

url,

data={

"consumerId":"bji0ejas9dc019phr4tj",

"queryParams":{

"sortby":"rlv.order%3Ddescending",

"maxpassages":"4",

"filter":"strict",

"groupby":"attr%3Dd.mode%3Ddeep.groups-on-page%3D100.docs-in-group%3D1",

"lr":"undefined",

"l10n":"ru",

"page":"0"

}

}

)

6.1.2. How to make xml POST request

xml = """

<?xml version="1.0" encoding="utf-8"?>

<request>

    <query>yandex</query>

    <sortby order="descending">tm</sortby>

    <groupings>

        <groupby attr="d" mode="deep" groups-on-page="100" docs-in-group="1" />

    </groupings>

    <maxpassages>4</maxpassages>

</request>

"""

headers = {'Content-Type': 'application/xml'} # set what your server accepts

requests.post('https://yandex.ru/search/xml?filter=strict&l10n=ru', data=xml, headers=headers)