您好,欢迎访问一九零五行业门户网

根据关键字 获取网站百度排名

[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"[^>]*>[\s\s]*?<\/table>/i',$contents,$rs); foreach($rs[0] as $k=>$v){ $px++; if(strstr($v,$url)){ $rsstate = true; preg_match_all('/<h3[\s\s]*?(<a[\s\s]*?<\/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>'; //print_r($rs_t);die; echo $rs_t[1][0]; //echo iconv('gbk','utf-8//ignore',$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=utf-8" /> <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>
2. [图片] 123.png
其它类似信息

推荐信息