利用网站的sitemap.xml和宝塔面板的监控功能实现定时推送文章到百度站长中心,实现快速收录。
一、在网站根目录新建一个文件夹,在文件夹新建一个 PHP 文件。
二、填写网站 sitemap.xml 地址和百度的推送接口(http://data.zz.baidu.com/urls?site=你的网站&token=你的),没token的 百度资源站长 前去获取。
三、把文件地址添加到宝塔定时任务,选择访问 URL,自定义执行时间后,保存即可。

例如:博主新建了sl的文件夹,文件夹内新建site.php 所以url地址为:72ph.com/sl/site.php

成功会返回
{"remain": 今日剩余数,"success": 推送成功数} 的。详情可以访我的url:72ph.com/sl/site.php参考成功效果

下面代码块中网站和sitemap地址记得替换

<?php
header('Content-Type:text/html;charset=utf-8');
$xmldata =file_get_contents("https://72ph.com/index.php/sitemap.xml");
$xmlstring = simplexml_load_string($xmldata,'SimpleXMLElement',LIBXML_NOCDATA);
$value_array = json_decode(json_encode($xmlstring),true);
$url = [];
for ($i =0;$i < count($value_array['url']);$i++){
    echo $value_array['url'][$i]['loc']."<br/>";
    $url[]= $value_array['url'][$i]['loc'];
}
$api ='http://data.zz.baidu.com/urls?site=72ph.com&token=你的';
$ch = curl_init();
$options = array(
   CURLOPT_URL => $api,
   CURLOPT_POST => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_POSTFIELDS => implode("\n",$url),
   CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),
);
curl_setopt_array($ch, $options);
$result =curl_exec($ch);
echo $result;
?>
最后修改:2022 年 06 月 08 日
如果觉得我的文章对你有用,请随意赞赏