🌐
经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用
点我优惠购买
🚀
拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多
点我优惠购买
🛡️
稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少
点我优惠购买
文章最后更新时间:2023年05月07日已超过1178天没有更新。
使用PHP命令脚本批量抓取百度搜索url用法 php.exe 1.php “关键词” “抓取页数”结果将保存在同目录下bAIdu.txt 如没有这个文件请手动创建PHP
[yk_WeChatFans]
<?php error_reporting(0); @$keyWord = $argv[1]; @$zpage = $argv[2]; if((!$keyword) or (!$zpage)){ die(‘ReqUIre keyword and page’); } $keyword = urlencode($keyword); for($p=0;$p<$zpage;$p++){ $url = ‘http://www.baidu.com/s?wd=’.$keyword.’&pn=’.$p.’0&oq=1&tn=baiduhome_pg&ie=utf-8&rsv_idx=2&rsv_pq=8292c42600001067&rsv_t=5e14MUzgVAGXxjHEqvWPfyBfPeJioaXg83h6Bm5Nlfi4ScTL4Qg1IKNLNtIEbbmFKHyl&f=8&rsv_bp=1&rsv_spt=1′; $txt = file_get_contents($url); preg_match_all(‘/(data)(-)(tools)(=)(\’)(\{)(“title”)(:)(“)((.+))(“)(,)(“url”)(:)(“)((.+))(“)(\})(\’)/i’,$txt,$matches); for($i=0;$i<count($matches[0]);$i++){ $json = str_replace(‘data-tools=’,”,$matches[0][$i]); $json = str_replace(‘\”,”,$json); $data = json_decode($json,true); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $data[‘url’]); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_AUTOREFERER,true); curl_setopt($ch, CURLOPT_TIMEOUT,5); curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Accept: */*’, ‘User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)’, ‘Connection: Keep-Alive’)); $header = curl_exec($ch); curl_close($ch); $header = explode(“\n”,$header); $num = array_find($header,’Location:’); $header = explode(‘: ‘,$header[$num]); $link = trim($header[1]); //if(stristr($link,’baidu.com’)){ //continue; //} file_put_contents(‘baidu.txt’,$data[‘title’].”\r\n”.$link.”\r\n”,FILE_APPEND); $a = $i+1; echo $a.’ Complete!’.”\n”; } $b = $p+1; echo ‘Page’.$b.’Complete!’.”\n”; } echo ‘Complete!’.”\n”; function array_find($array,$word){ foreach($array AS $num => $key){ if(strpos($key,$word) !== false){ return $num; break; } } } ?>
[/yk_WeChatFans]
文章版权声明:除非注明,否则均为AI虎哥的工具库原创文章,转载或复制请以超链接形式并注明出处。



还没有评论,来说两句吧...