php获取关键字百度所在页码,我们做站!希望看到关键字在搜索所在的页数,就是排名!我们不可能一个一去查!用php很方便就获取到!看案例
- <?php
- $page=4; //页面数
- $domain="www.phpzy.com"; //域名
- $title="php资源"; //搜索词语
- $title=urlencode($title);
- for($n=0;$n<=$page;$n++){
- $a=(10*$n);
- $url="http://www.baidu.com/s?wd=$title&pn=$a";
- $file=fopen($url,"r");
- while(!feof($file))
- {
- $result.=fgets($file,9999);
- }
- //百度快照时间
- //echo $result;
- if(strpos($result,$domain)==true){
- $nb=$n+1;
- echo '在第'.$nb.'页<br>';
- $n=$page;
- $url1=$url; //记录找到结果的URL
- }else{
- $nb=$n+1;
- echo '第'.$nb.'没有找到<br>';
- }
- fclose($file);
- }
- ?>