[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
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor