PHPcurl模拟UA2020年文章是否被百度收录检测代码(附API)修复

PHP curl UA模拟2020年文章是否被百度收录检测代码(附API)

已修复百度安全验证码导致无法正确推送文章及查询百度收录API


前言:

之前基本采用的是Typecho添加“百度是否收录”判断的方法

最近发现该方法经常没有效果,要么就是查询失败,无法正常反馈百度搜索内容\

今天正好有空对这个typecho文章是否被百度收录检测代码附API修复更新,测试了一下完美推送地址即检测收录,PHPcurl模拟UA的方式绕过百度的反爬虫百度安全检测

如下图所示,成功过百度安全验证:

image.png

百度收录检测API反馈测试:

百度收录API测试链接为:

https://www.proyy.com/api/baidu_check/index.php?domain=https://www.proyy.com/15300.html

百度收录API测试反馈为:

{"code":200,"url":"https:\/\/www.proyy.com\/15300.html","msg":"该URL已被百度收录!","number":"15800"}

百度收录API测试截图为:

image.png

2020最新typecho百度收录查询修复代码及API:

1、typecho调用查询

在网站模板post.php文件中加入,CSS样式麻烦自行修改吧.

<!--一一网络百度收录修复-->
<li class="meta-baidu"><span class="post-icons"><i class="glyphicon glyphicon-refresh" id="baidu_icon"></i></span><span class="meta-value" id="baidu_result">loading</span></li>

2、post.php头部添加JQ判断收录

需要在文章post.php文件的头部加入,并且需要引入jquery哦,如果主体已经引用,那么久不用重复引用jquery了,反馈的文字可以自己定义。

<script>
        function baidu_check(){
            $.getJSON("https://www.proyy.com/api/baidu_check/index.php?domain="+window.location.href,function(result){
                if (result.code == 200) {
                    $('#baidu_icon').removeClass('glyphicon-refresh');
                    $('#baidu_icon').addClass('glyphicon-ok-circle');
                    $('#baidu_result').text('百度已收录');
                }else if(result.code == 403){
                    $('#baidu_icon').removeClass('glyphicon-refresh');
                    $('#baidu_icon').addClass('glyphicon-info-sign');
                    $('#baidu_result').text('百度未收录');
                }else{
                    $('#baidu_icon').removeClass('glyphicon-refresh');
                    $('#baidu_icon').addClass('glyphicon-remove-circle');
                    $('#baidu_result').text('查询收录失败');
                }
            });
        }
        baidu_check();
</script>

3、2020最新typecho百度收录查询修复API调用源码:

最新修复API源码如有需要请邮件至admin@proyy.com

可以直接使用我的API

https://www.proyy.com/api/baidu_check/index.php?domain=https://www.proyy.com/15300.html

旧版检测API源码,检测后并不可用:

<?php
/**
 * Baidu
 * @editer: Weifeng
 * @link: https://wfblog.net
 * @version: 1.0
 */
error_reporting(0);
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
$domain = @$_GET['domain'];
if(!isset($domain) || empty($domain) || $domain==''){
    $data = array(
        "code" => false,
        "msg" => "未传入请求参数!"
    );
    echo json_encode($data,JSON_UNESCAPED_UNICODE);
    exit;
}
$data = checkBaidu($domain);
echo json_encode($data,JSON_UNESCAPED_UNICODE);
function checkBaidu($url){
    $header = array(
        "Host:www.baidu.com",
        "Content-Type:application/x-www-form-urlencoded",//post请求
        "Connection: keep-alive",
        "Referer:https://www.baidu.com",
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
    );
    $url = 'https://www.baidu.com/s?ie=UTF-8&wd='.urlencode($url).'&usm=3&rsv_idx=2&rsv_page=1';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    if(strpos($output, '没有找到') || strpos($output, '很抱歉')){
        $data = array(
            "code" => 403,
            "msg" => "该域名暂时未被百度收录!"
        );
    }else{
        $number = GetBetween($output,'<span class="nums_text">百度为您找到相关结果约','个</span>');
        if(empty($number) || $number == 0){
            $number = GetBetween($output,'<b>找到相关结果数约','个</b></p>');
            if(empty($number) || $number == 0){
                $data = array(
                    "code" => false,
                    "msg" => "获取百度收录失败!"
                );
                return $data;
            }
        }
        $data = array(
            "code" => 200,
            "msg" => "该域名已被百度收录!",
            "number" => str_replace(',','',$number)
        );
    }
    return $data;
}
function GetBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
}
?>
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享