php抓取网站关键词在百度具体排名 代码实例

php代码匹配某个网站及关键词在百度的搜索排名

<?php  function s($keyword,$url,$page = 1){      static $px = 0;      $rsState = false;           $enKeyword = urlencode($keyword);      $firstRow = ($page - 1) * 10;           if($page > 10){          die('10页之内没有该网站排名..end');      }        $contents = file_get_contents("http://www.baidu.com/s?wd=$enKeyword&&pn=$firstRow");      preg_match_all('/<table [^>]*?class="result"[^>]*>[sS]*?< /table>/i',$contents,$rs);      foreach($rs[0] as $k=>$v){          $px++;          if(strstr($v,$url)){              $rsState = true;              preg_match_all('/<h3 [sS]*?(<a[sS]*?</a>)/',$v,$rs_t);              echo '当前 "' . $url . '" 在百度关键字 "' . $keyword . '" 中的排名为:' . $px;              echo '<br />';              echo '第' . $page . '页;第' . ++$k . "个<a target='_blank' href='http://www.baidu.com/s?wd=$enKeyword&&pn=$firstRow'>进入百度</a>";              echo '<br />';              echo $rs_t[1][0];              break;          }      }      unset($contents);      if($rsState === false){          s($keyword, $url,++$page);      }  }  if(isset($_POST['submit'])){           $time = explode(' ',microtime());      $start = $time[0] + $time[1];        $url = $_POST['url'];      if( count(explode('.',$url)) < = 2){            $url = ltrim($url,'http://');          $url = 'www.' . $url;      }        s($_POST['keyword'],$url);           $endtime = explode(' ',microtime());        $end = $endtime[0] + $endtime[1];        echo '<hr>';      echo '程序运行时间: ';      echo $end - $start;      die();  }    ?>    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta http-equiv="Content-Type" content="text/html; charset=gbk" />  <title>抓取排名</title>    </head>    <body>  <form action="" method="post">      <ul>          <li>              <span>关键字:</span><input type="text" name="keyword"/>          </li>          <li>              <span>url地址:</span><input type="text" name="url"/>          </li>          <li>              <input type="submit" name="submit" value="搜索"/>          </li>      </ul>       </form>  </body>  </html>  </h3></table>

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

php抓取网站关键词在百度具体排名 代码实例

`微信`扫码 加好友

链接到文章: https://gkxyz.com/phpzhuaquwangzhanguanjiancizaibaidujutipaiming-daimashili.html

推荐站点

评论已关闭