Submit URLs to Baidu via API
·
2 min read
·
220
Words
·
-Views
-Comments
I wanted Baidu to index more of my blog posts, so I set up API submissions. Here’s the process.
Get the API Token
Open Baidu Search Console, select your site, then Regular Inclusion → Resource Submission → API Submission. The token displayed there authorizes submissions—keep it secret.
Submit URLs
Example Node.js script for my Hugo blog; any language works.
const SITEMAP_FILE = path.join(__dirname, '../public/sitemap.xml'); // sitemap path
const BAIDU_API_URL = `http://data.zz.baidu.com/urls?site=1991421.cn&token=${process.env.BAIDU_ZZ_TOKEN}`; // Baidu submission endpoint
const MAX_URLS = 5; // max URLs per request
async function submitToBaidu(urls) {
try {
console.log('Submitting URLs', urls);
const response = await fetch(BAIDU_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'text/plain'
},
body: urls.join('\n') // newline-delimited list
});
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const data = await response.json();
console.log('Submit success:', data);
} catch (error) {
console.error('Submit failed:', error.message);
}
}
My Workflow
I run this script in GitHub Actions. Each build generates sitemap.xml
; the action grabs the newest N URLs and posts them to Baidu.
Common Questions
Daily Quota
- 10 URLs per day.
- Exceeding the quota returns HTTP 400.
Common 400 Errors
- Quota exceeded
- Invalid token
- Wrong
site
parameter (omit the protocol, e.g.site=1991421.cn
)
Closing Thoughts
Baidu isn’t my favorite, but it’s still worth submitting URLs for mainland readers. If you know a better method, leave a comment.