Home  >  Article  >  Backend Development  >  php中通过curl检测页面是否被百度收录_php技巧

php中通过curl检测页面是否被百度收录_php技巧

WBOY
WBOYOriginal
2016-05-17 08:55:09751browse

最近要对网站做个整理,需要检测网站内哪些页面没有被百度搜索引擎收录从而进行相关的调整。由于使用site命令一条条的去看实在是看不过来,就想到了使用php程序来批量处理一下,研究了一下,发现其实很简单,下面就将作者使用php实现的检测页面是否被百度收录的功能分享一下。

下面是具体代码:

复制代码 代码如下:

/*
* 检测网页是否被百度收录,返回1则表示收录 返回0表示没有收录
* @ param string $url 待检测的网址
*/
function checkBaiduInclude($url){
    $url='http://www.baidu.com/s?wd='.$url;
    $curl=curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
    $rs=curl_exec($curl);
    curl_close($curl);
    if(!strpos($rs,'抱歉,没有找到')){
        return 1;
    }else{
        return 0;
    }  
}

意思很简单了,比如需要检测 http://www.phpernote.com/javascript-function/833.html 这个网址是否被收录,则只需要:

checkBaiduInclude('http://www.phpernote.com/javascript-function/833.html');结果自己去看吧。

本文转载自: PHP程序员笔记

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn