php curl 检测网页是否被百度收录_PHP教程

WBOY
Lepaskan: 2016-07-20 11:15:19
asal
687 orang telah melayarinya

<?<span php
</span><span /*</span><span 
* 检测百度是否收录网页 curl模式
* @ param string $url传入的url
* powed by Jin Gao<br />* return int (1 收录 0 不收录)
</span><span */</span>
<span function</span> checkBaidu(<span $url</span><span ){
</span><span $url</span>='http://www.baidu.com/s?wd='.<span $url</span><span ;

</span><span $curl</span>=<span curl_init();
curl_setopt(</span><span $curl</span>,CURLOPT_URL,<span $url</span><span );
curl_setopt(</span><span $curl</span>,CURLOPT_RETURNTRANSFER,1<span );
</span><span $rs</span>=curl_exec(<span $curl</span><span );
curl_close(</span><span $curl</span><span );

</span><span $arr</span>=<span parse_url</span>(<span $url</span><span );

</span><span if</span>(<span strpos</span>(<span $arr</span>['query'],'http://'<span )){
</span><span $arr</span>['query']=<span str_replace</span>('http://','',<span str_replace</span>('wd=','',<span $arr</span>['query'<span ]));
}</span><span else</span><span {
</span><span $arr</span>['query']=<span str_replace</span>('wd=','',<span $arr</span>['query'<span ]);
}

</span><span if</span>(<span strpos</span>(<span $arr</span>['query'],'?'<span )){
</span><span $str</span>=<span strstr</span>(<span $arr</span>['query'],'?'<span );
</span><span $arr</span>['query']=<span str_replace</span>(<span $str</span>,'',<span $arr</span>['query'<span ]);
}

</span><span if</span>(<span strpos</span>(<span $arr</span>['query'],'/'<span )){
</span><span $narr</span>=<span explode</span>('/',<span $arr</span>['query'<span ]);
</span><span $arr</span>['query']=<span $narr</span>[0<span ];
}

</span><span if</span>(<span strpos</span>(<span $rs</span>,'<b>'.<span $arr</span>['query'].'</b>'<span )){
</span><span return</span> 1<span ;
}</span><span else</span><span {
</span><span return</span> 0<span ;
} 
}

</span><span echo</span> checkBaidu('http://www.ahjk.cn/'<span );
</span>?>
Salin selepas log masuk

另一种是最蛋疼的方法 如图

可以通过 preg_match 函数检测 是否有 “” 这个文字来判断是否收录

<span function</span> checkbaidu(<span $key</span><span ){
        </span><span $url</span>="http://www.baidu.com/s?wd=".<span $key</span><span ;
        </span><span $html</span> = @<span file_get_contents</span>(<span $url</span><span );
        </span><span $html</span> = <span iconv</span>('utf-8','gbk//TRANSLIT',<span $html</span><span );
        </span><span if</span>(<span preg_match</span>('/(抱歉,没有找到与)/', <span $html</span><span )) {
          </span><span return</span> 0<span ;
        } </span><span else</span><span  {
                 </span><span return</span> 1<span ;
        }
}            </span>
Salin selepas log masuk

 

 

  本人已经测试过了,是完全可以的。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440181.htmlTechArticle? * return int (1 收录 0 不收录) checkBaidu( ='http://www.baidu.com/s?wd='. = ,CURLOPT_URL, ,CURLOPT_RETURNTRANSFER,1 =curl_exec( = ( ( ( ['query'],'http://' ['query']= ('http...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan