每次提交網(wǎng)站鏈接至百度收錄時(shí)每一條都要把文章鏈接復(fù)制過(guò)去,很麻煩很費(fèi)事庶柿,使用下面的方法配合寶塔計(jì)劃任務(wù)每天準(zhǔn)時(shí)自動(dòng)提交網(wǎng)站全站鏈接省事!
教程
首先在網(wǎng)站根目錄下新建一個(gè)PHP文件秽浇,復(fù)制一下代碼至文件浮庐,填寫(xiě)修改網(wǎng)站sitemap.xml地址和百度推送接口!
代碼
<?php
header('Content-Type:text/html;charset=utf-8');
$xmldata =file_get_contents("https://wuzuhua.cn/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=https://wuzuhua.cn&token=O4e5NmFo9jv5PrkF';
$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;?>
把創(chuàng)建好的PHP文件鏈接添加到寶塔定時(shí)任務(wù)柬焕,選擇訪(fǎng)問(wèn) URL审残,執(zhí)行時(shí)間自定義后,如同下圖保存即可斑举!
成功示例
成功會(huì)返回 {“remain”: 今日剩余數(shù)搅轿,”success”: 推送成功數(shù)} 的。
效果
文章來(lái)源:https://wuzuhua.cn/3996.html