Home > Backend Development > PHP Tutorial > How to detect whether a page is included in Baidu through curl in php

How to detect whether a page is included in Baidu through curl in php

怪我咯
Release: 2023-03-12 22:54:01
Original
1283 people have browsed it

I need to organize the website recently. I need to detect which pages in the website are not indexed by the Baidu search engine and make relevant adjustments. Since I couldn’t see it clearly by using the site command one by one, I thought of using a PHP program to batch process it

I need to organize the website recently and need to detect which pages in the website have not been searched by BaiduIndexThe engine is included to make relevant adjustments. Since I couldn’t see it clearly by using the site command one by one, I thought of using the PHP program to batch process it. After some research, I found that it is actually very simple. Here is the author’s implementation of using PHP to detect whether a page has been included in Baidu. Share the function.

The following is the specific code:

The code is as follows:

<?php
/*
* 检测网页是否被百度收录,返回1则表示收录 返回0表示没有收录
* @ param string $url 待检测的网址
*/
function checkBaiduInclude($url){
    $url=&#39;http://www.baidu.com/s?wd=&#39;.$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,&#39;抱歉,没有找到&#39;)){
        return 1;
    }else{
        return 0;
    }   
}
Copy after login

The meaning is very simple, for example, you need to detect http://www.phpernote.com /javascript-function/833.html Whether this URL is included, you only need to:

checkBaiduInclude('http://www.phpernote.com/javascript-function/833.html ');Go and see for yourself.

The above is the detailed content of How to detect whether a page is included in Baidu through curl in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template