Submit URLs to Baidu in Style

Baidu introduced a fancier yet kind of geeky way of URL submission

Posted by Ryan Chooai

When submitting URLs to search engines, the two most common ways are single URL submission and sitemap submission.

For example, on Baidu:

  1. You can do a quick manual submission using our own Baidu submission tool;
  2. You can also submit your sitemap to Baidu in Baidu Webmaster Tools. This is the go-to method for most webmasters.

But this summer, Baidu introduced a fancier yet kind of geeky way of URL submission – bulk submission via the direct submission API.

By utilizing Baidu’s direct submission API, webmasters don’t have to sit there waiting for Baidu to come to your site and find new URLs on your site any more – now you can directly push new URLs to Baidu, which can potentially make the indexation process much quicker.

Isn’t that cool? Okay, we have created a simple guide to help you get started quickly.

Overview

First, you need a Baidu Webmaster Tools account. Baidu assigns each webmaster tools account a unique token, which is part of the request URL for URL submission.

You can find you own access token by going to “链接提交” in your BWT account.

For example, if your website is www.a.com, your access URL will be something like:

http://data.zz.baidu.com/urls?site=www.a.com&token=your-private-token

Parameters Required Type Notes
site yes string a verified website in Baidu Webmaster Tools
token yes string Your own private token

How to Use the API – Sample Codes

Curl Example

Put the URLs in a file named urls.txt. One URL per line.

curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=www.a.com&token=your-private-token"

HTTP Post Method Example

POST /urls?site=www.a.com&token=your-private-token HTTP/1.1
User-Agent: curl/7.12.1
Host: data.zz.baidu.com
Content-Type: text/plain
Content-Length: 83
http://www.a.com/1.html
http://www.a.com/2.html

PHP Example

$urls = array(
'http://www.a.com/1.html',
'http://www.a.com/2.html',
);
$api = 'http://data.zz.baidu.com/urls?site=www.a.com&token=your-private-token';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS =>implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;

Ruby Example

require 'net/http'
urls = ['http://www.a.com/1.html', 'http://www.a.com/2.html']
uri = URI.parse('http://data.zz.baidu.com/urls?site=www.a.com&token=your-private-token')
req = Net::HTTP::Post.new(uri.request_uri)
req.body = urls.join("\n")
req.content_type = 'text/plain'
res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
puts res.body

Python Example

import requests
seed_file = open('urls.txt', 'r')
urllist = '\n'.join(seed_file.readlines())
r = requests.post(
"http://data.zz.baidu.com/urls?site=www.a.com&token=your-private-token",
data=urllist,
headers={'content-type':'text/plain'})
print r.text

Responses

Successful submission

{ "remain":4999998, "success":2, "not_same_site":[], "not_valid":[] }

String Required Type Notes
success yes int no. of URLs that are successfully submitted
remain yes int no. of URLs left in the daily quota
not_same_site no array not a verified site in your BWT account
not_valid no array invalid URLs submitted

Failed submission

{ "error":401, "message":"token is not valid" }

String Required Type Notes
error yes int error code, usually a 4xx HTTP status code
message yes string error description

Using WordPress or Discuz?

To simplify the URL submission process, Baidu has released official plugins for WordPress and Discuz. The plugins not only submit the site’s URLs to Baidu, but also make the submitted data in a Baidu-friendly way.

You can grab the plugins here: http://zhanzhang.baidu.com/dataplug/

Related articles:

baidu seo guide

Stay up to date