每次提交网站链接至百度收录时每一条都要把文章链接复制过去,很麻烦很费事,使用下面的方法配合宝塔计划任务每天准时自动提交网站全站链接省事!
教程
- 首先在网站根目录下新建一个PHP文件,复制一下代码至文件,填写修改网站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']."
"; - $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;?>
- 把创建好的PHP文件链接添加到宝塔定时任务,选择访问 URL,执行时间自定义后,如同下图保存即可!
成功示例
- 成功会返回 {“remain”: 今日剩余数,”success”: 推送成功数} 的。
效果
文章来源:wuzuhua.cn/3996.html
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.