NAVNavbar
Logo
cURL php NodeJS Python cSharp

Get {{up_se_name}} {{up_se_type}} SERP Results by id

Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforseo.com/api-access

<?php
// You can download this file from here https://cdn.dataforseo.com/v3/examples/php/php_RestClient.zip
require('RestClient.php');
$api_url = 'https://api.dataforseo.com/';
try {
	// Instead of 'login' and 'password' use your credentials from https://app.dataforseo.com/api-access
	$client = new RestClient($api_url, null, 'login', 'password');
} catch (RestClientException $e) {
	echo "n";
	print "HTTP code: {$e->getHttpCode()}n";
	print "Error code: {$e->getCode()}n";
	print "Message: {$e->getMessage()}n";
	print  $e->getTraceAsString();
	echo "n";
	exit();
}
try {
	$result = array();
	// #1 - using this method you can get a list of completed tasks
	// GET /v3/serp/{{low_se_name}}/{{low_se_type}}/tasks_ready
	// in addition to '{{low_se_name}}' and '{{low_se_type}}' you can also set other search engine and type parameters
	// the full list of possible parameters is available in documentation
	$tasks_ready = $client->get('/v3/serp/{{low_se_name}}/{{low_se_type}}/tasks_ready');
	// you can find the full list of the response codes here https://docs.dataforseo.com/v3/appendix/errors
	if (isset($tasks_ready['status_code']) AND $tasks_ready['status_code'] === 20000) {
		foreach ($tasks_ready['tasks'] as $task) {
			if (isset($task['result'])) {
				foreach ($task['result'] as $task_ready) {
					// #2 - using this method you can get results of each completed task
					// GET /v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/regular/$id
					if (isset($task_ready['endpoint_regular'])) {
						$result[] = $client->get($task_ready['endpoint_regular']);
					}
					// #3 - another way to get the task results by id
					// GET /v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/regular/$id
					/*
					if (isset($task_ready['id'])) {
						$result[] = $client->get('/v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/regular/' . $task_ready['id']);
					}
					*/
				}
			}
		}
	}
	print_r($result);
	// do something with result
} catch (RestClientException $e) {
	echo "n";
	print "HTTP code: {$e->getHttpCode()}n";
	print "Error code: {$e->getCode()}n";
	print "Message: {$e->getMessage()}n";
	print  $e->getTraceAsString();
	echo "n";
}
$client = null;
?>

The above command returns JSON structured like this:

{
  "version": "0.1.20201026",
  "status_code": 20000,
  "status_message": "Ok.",
  "time": "0.1162 sec.",
  "cost": 0,
  "tasks_count": 1,
  "tasks_error": 0,
  "tasks": [
    {
      "id": "10301432-1535-0066-0000-e749b9e61585",
      "status_code": 20000,
      "status_message": "Ok.",
      "time": "0.0453 sec.",
      "cost": 0,
      "result_count": 1,
      "path": [
        "v3",
        "serp",
        "baidu",
        "organic",
        "task_get",
        "regular",
        "10301432-1535-0066-0000-e749b9e61585"
      ],
      "data": {
        "api": "serp",
        "function": "task_get",
        "se": "baidu",
        "se_type": "organic",
        "location_code": 2156,
        "keyword": "iphone 12",
        "tag": "some_string_123",
        "device": "desktop",
        "os": "windows"
      },
      "result": [
        {
          "keyword": "iphone 12",
          "type": "organic",
          "se_domain": "baidu.com",
          "location_code": 2156,
          "language_code": "zh_CN",
          "check_url": "http://www.baidu.com/s?wd=iphone%2012&rn=50&pn=0&ie=utf-8",
          "datetime": "2020-10-30 12:33:02 +00:00",
          "spell": null,
          "refinement_chips": null,
          "item_types": [
            "organic",
            "paid"
          ],
          "se_results_count": 57200000,
          "items_count": 95,
          "items": [
            {
              "type": "paid",
              "rank_group": 1,
              "rank_absolute": 1,
              "domain": "www.baidu.com",
              "title": "iPhone 12 - 百度百科",
              "description": null,
              "url": "http://www.baidu.com/link?url=dx63T9ukxStLyx18W3MV82RaWv62MPNdbH2z0vZevgNErOzmDTm8xoVg-BOjN8swjuOa_RtqLyc2qhTudUmvE1Nh5ntGkK1IqyqojRO6vxO",
              "breadcrumb": "baike.baidu.com/"
            },
            {
              "type": "organic",
              "rank_group": 2,
              "rank_absolute": 2,
              "domain": "www.baidu.com",
              "title": "iPhone12:没有意思_腾讯新闻",
              "description": "1天内  【任何转载不被许可,依照中华人民共和国《著作权法》追究违者法律责任】闹剧结束了……从最高加价2000,每小时报价一次到现在的折价卖,宁可亏欠也要转...",
              "url": "http://www.baidu.com/link?url=j6XHiSMbbn0tHh1mVpjNhEC2Y1eyLFwDa2BNzrxJEckjcUqGaFrhfSDYxmrbBz_6LkLccpcXB5p70XpZyQHuea",
              "breadcrumb": "腾讯网"
            },
            {
              "type": "organic",
              "rank_group": 3,
              "rank_absolute": 3,
              "domain": "www.baidu.com",
              "title": "购买iPhone 12 Pro 和 iPhone 12 Pro Max - Apple (中国大...",
              "description": "1天前  从Apple 购买全新 iPhone 12 Pro 和 iPhone 12 Pro Max。在线选购,享受免费送货服务。... iPhone 12 Pro 和 iPhone 12 Pro Max 可防溅、抗水、防尘,在受控实...",
              "url": "http://www.baidu.com/link?url=IVCs-Wr3vAWPMXqSZ2FPx9EdrhbBybdcNwOCH05Y10jmOTUVN3U5KM9hCql1qoWeGZ-YTnu_GjQIgs4OcIoava",
              "breadcrumb": "Apple官方网站"
            },
            {
              "type": "organic",
              "rank_group": 4,
              "rank_absolute": 4,
              "domain": null,
              "title": "iphone 12 - 视频大全 - 高清在线观看",
              "description": null,
              "url": null,
              "breadcrumb": null
            },
            {
              "type": "organic",
              "rank_group": 5,
              "rank_absolute": 5,
              "domain": "www.baidu.com",
              "title": "iPhone12,居然这么强 - 知乎",
              "description": "这几天供应链方面传出,苹果将对新 iPhone 的厚度进行控制, iPhone 12 或许只有 7.4 毫米厚。 机哥瞅了眼,目前 iPhone 11 Pro 的厚度是 8.1 毫米,而 iPhone...",
              "url": "http://www.baidu.com/link?url=Zepp51TMFPaiEdJEpOaGYVDR1C5mAJ-_SusA2PCMd6on-d96RguuB5_cL4IkUVUapwHXdgVb18zJkcXBkL78YzzLHbLX8LuJq9ipMAO9FOm",
              "breadcrumb": "知乎"
            },
            {
              "type": "organic",
              "rank_group": 6,
              "rank_absolute": 6,
              "domain": "www.baidu.com",
              "title": "苹果iPhone12-苹果iPhone12怎么样-报价参数-图片点评-天极网",
              "description": "7天前  iPhone 12 支持MagSafe磁吸充电,咔嗒一贴即合,磁体之间可自动精准对齐,同时无线充电的速度也更快了",
              "url": "http://www.baidu.com/link?url=VKxjGBMc6-dCTjRjraw_GgHCTdExaaZDft7GVBQG0SDIRHFo9jH8DRQpCy_u1dINk_c1Ehs9cxGOaiQU7hesfK",
              "breadcrumb": "天极网资讯"
            },
            {
              "type": "organic",
              "rank_group": 7,
              "rank_absolute": 7,
              "domain": "www.baidu.com",
              "title": "【iPhone12】iPhone12上市时间_iPhone12最新消息_iPhone12...",
              "description": "2020年10月22日  手机中国小道消息提供 iPhone12 全面信息,包括 iPhone12 报价、参数、配置、网友点评、各种图赏等信息,为您购买 iPhone12 提供最有价值的参考信息,帮您全面了解 iPhone12 。",
              "url": "http://www.baidu.com/link?url=x4RyBDJPoOhBtaSMalC8ap_XFnCCTrMKy_rAJx8NrJIGsq6CN5-K9Y_BlD7WW_kz",
              "breadcrumb": "CNMO手机中国"
            },
            {
              "type": "organic",
              "rank_group": 8,
              "rank_absolute": 8,
              "domain": "www.baidu.com",
              "title": "iPhone 12最新确定:2个好消息和1个坏消息",
              "description": "2020年9月14日  苹果最近将发布的旗舰机共有4款, iPhone12 全系列将采用高通提供的5G解决方案,其中 iPhone12 、 iPhone12 plus和 iPhone12 pro、 iPhone12 pro max最大的区别在于前面两者...",
              "url": "http://www.baidu.com/link?url=5mCurRBfz6smvnrrtKw6CgS1-N7u8XLLmuaoMBEn1Ul-HofUFHIpZ1D_JwaUOtngIwfvQ_VsfmdawmHhiZUIUhuwtVYn6hQPX4yLnNjglyO",
              "breadcrumb": "摄影单反相机点评"
            },
            {
              "type": "organic",
              "rank_group": 9,
              "rank_absolute": 9,
              "domain": "www.baidu.com",
              "title": "iPhone 12 | iPhone中文网",
              "description": "2020年8月31日  iPhone 中文网为大家提供 iPhone XS Max, iPhone 8,XR等新品苹果 iPhone 手机的新闻资讯, iPhone 软件游戏推荐,苹果周边硬件评测等内容,及时报道 苹果手机 及其他...",
              "url": "http://www.baidu.com/link?url=XlbG8hA7UfV89t96vBAAUUb4pv0Lcq4p6b3XVXbhTK8kbuhfBqmcLgX8EdzvUXarUx3Wb54NHAtsM-sDbylqLa",
              "breadcrumb": "iphone.tgbus.com/list/iPhone...12"
            },
            {
              "type": "organic",
              "rank_group": 10,
              "rank_absolute": 10,
              "domain": "www.baidu.com",
              "title": "iPhone 12全线跌破发行价?真相在这儿……_媒体_澎湃新闻-T...",
              "description": "22小时前  原创 蔡淑敏 国际金融报 收录于话题#苹果2# iPhone 121 距离 iPhone 12 发布会已经过去了两周,但网络上对这款手机的关注度依旧不减。 近期,iP",
              "url": "http://www.baidu.com/link?url=sUx8n1NS_Vwz0QNioUImpSh586H8Ko9Dr7BSvCvE94X_v9XqcrzwGZ8i63_Od0mY3MDcRvcrjUFImo0uQDPKGK",
              "breadcrumb": "澎湃新闻"
            }
          ]
        }
      ]
    }
  ]
}

Description of the fields for sending a request:

Field name Type Description
id string task identifier
unique task identifier in our system in the UUID format
you will be able to use it within 30 days to request the results of the task at any time

‌‌‌‌
‌‌As a response of the API server, you will receive JSON-encoded data containing a tasks array with the information specific to the set tasks.

You can also get all available SERP features and possible extra elements by making a request to the following Sandbox URL:
https://sandbox.dataforseo.com/v3/serp/baidu/organic/task_get/regular/00000000-0000-0000-0000-000000000000
The response will include all available items in the Baidu Organic SERP Regular endpoint with the fields containing dummy data.
You won’t be charged for using Sandbox endpoints.

Description of the fields in the results array:

Field name Type Description
version string the current version of the API
status_code integer general status code
you can find the full list of the response codes here
Note: we strongly recommend designing a necessary system for handling related exceptional or error conditions
status_message string general informational message
you can find the full list of general informational messages here
time string execution time, seconds
cost float total tasks cost, USD
tasks_count integer the number of tasks in the tasks array
tasks_error integer the number of tasks in the tasks array that were returned an error
tasks array array of tasks
        id string task identifier
unique task identifier in our system in the UUID format
        status_code integer status code of the task
generated by DataForSEO; can be within the following range: 10000-60000
you can find the full list of the response codes here
        status_message string informational message of the task
you can find the full list of general informational messages here
        time string execution time, seconds
        cost float cost of the task, USD
        result_count integer number of elements in the result array
        path array URL path
        data object contains the same parameters that you specified in the POST request
        result array array of results
            keyword string keyword received in a POST array
keyword is returned with decoded %## (plus symbol ‘+’ will be decoded to a space character)
            type string search engine type in a POST array
            se_domain string search engine domain in a POST array
            location_code integer location code in a POST array
            language_code string language code in a POST array
            check_url string direct URL to search engine results
you can use it to make sure that we provided accurate results
            datetime string date and time when the result was received
in the UTC format: “yyyy-mm-dd hh-mm-ss +00:00”
example:
2019-11-15 12:57:46 +00:00
            spell object autocorrection of the search engine
if the search engine provided results for a keyword that was corrected, we will specify the keyword corrected by the search engine and the type of autocorrection
                keyword string keyword obtained as a result of search engine autocorrection
the results will be provided for the corrected keyword
                type string type of autocorrection
possible values:
did_you_mean, showing_results_for, no_results_found_for, including_results_for
            refinement_chips object search refinement chips
equals null
            item_types array types of search results found in SERP
contains types of all search results (items) found in the returned SERP
possible item types:
organic, paid
            se_results_count integer total number of results in SERP
            items_count integer the number of results returned in the items array
            items array items in SERP
            ‘organic’ element in SERP
                type string type of element = ‘organic’
                rank_group integer group rank in SERP
position within a group of elements with identical type values
positions of elements with different type values are omitted from rank_group
                rank_absolute integer absolute rank in SERP
absolute position among all the elements found in SERP
                domain string domain in SERP
                title string title of the results element in SERP
                description string description of the results element in SERP
                url string relevant URL in SERP

by default, the URLs in Baidu results are encoded by the search engine,
for example:
http://www.baidu.com/link?url=KQt6LSwU5OHnPtB8210R8flBP40grY6lTPxH_0UO7S2kgiZMTmw3ztV0hCo5c1kL

if you want to get direct URL, specify get_website_url as true when setting a task;
note that if you use the get_website_url field the charge per task will be multiplied by 10 as our system runs a separate request for each ranked website to return its direct URL

                breadcrumb string breadcrumb in SERP
            ‘paid’ element in SERP
                type string type of element = ‘paid’
                rank_group integer group rank in SERP
position within a group of elements with identical type values
positions of elements with different type values are omitted from rank_group
                rank_absolute integer absolute rank in SERP
absolute position among all the elements found in SERP
                domain string domain in SERP
                title string title of the results element in SERP
                description string description of the results element in SERP
                url string relevant URL in SERP

by default, the URLs in Baidu results are encoded by the search engine,
for example:
http://www.baidu.com/link?url=KQt6LSwU5OHnPtB8210R8flBP40grY6lTPxH_0UO7S2kgiZMTmw3ztV0hCo5c1kL

if you want to get direct URL, specify get_website_url as true when setting a task;
note that if you use the get_website_url field the charge per task will be multiplied by 10 as our system runs a separate request for each ranked website to return its direct URL

                breadcrumb string breadcrumb in SERP

‌‌