自动推送是百度搜索资源平台为提高站点新增网页发现速度推出的工具,安装自动推送JS代码的网页,在页面被访问时,页面URL将立即被推送给百度.

百度自动推送工具代码:
需要在每个页面的HTML代码中包含以下自动推送JS代码:

<script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script>

如果站长使用PHP语言开发的网站,可以按以下步骤操作:
[1] - 创建名为 baidu_js_push.php 的文件,文件内容是上述自动推送JS代码;
[2] - 在每个PHP模板页文件中的 <body> 标记后面添加一行代码:
<?php include_once("baidu_js_push.php") ?>

基于自动推送的实现原理问题,当新页面每次被浏览时,页面URL会自动推送给百度,无需再汇总URL再进行主动推送操作. 借助用户的浏览行为来触发推送动作,省去了人工操作的时间.

在上述推送代码中访问时会加载两个JavaScript 脚本,打开脚本内容了解到只是加载 gif 图片.
加载 gif 图片时,同时也会将窗口所在地址提交给百度搜索.

百度自动推送工具代码优化版

// 百度主动推送代码升级版 <script> (function(){ var canonicalURL, curProtocol; //Get the tag var x=document.getElementsByTagName("link"); //Find the last canonical URL if(x.length > 0){ for (i=0;i<x.length;i++){ if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){ canonicalURL=x[i].href; } } } //Get protocol if (!canonicalURL){ curProtocol = window.location.protocol.split(':')[0]; } else{ curProtocol = canonicalURL.split(':')[0]; } //Get current URL if the canonical URL does not exist if (!canonicalURL) canonicalURL = window.location.href; //Assign script content. Replace current URL with the canonical URL !function(){var e=/([http|https]://[a-zA-Z0-9_.]+.baidu.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})(); </script>

直接采用优化版链接自动提交代码替换百度链接自动提交代码即可.

Last modification:October 9th, 2018 at 09:31 am