php 自製以simple_html_dom為基礎的爬蟲一隻v1.0
continue
html
quot
the
一直以來網頁解析和爬蟲的製作熱情絲毫未減今天用開源的simple_html_dom.php解析框架做了一隻爬蟲:
<?php /* *.Pho spider v1.0 *.Written by Radish.ghost 2015.1.20 */ //error_reporting(1); //close error report //curl model //I will realize it in later versions include_once("simple_html_dom.php"); $html=file_get_html('http://www.baidu.com');//The url which you want dig $tmp=array();//Save the url in the first dig foreach($html->find('a') as $e) { $f=$e->href; //if($f[10]==':')continue; if($f[0]=='/')$f='http://www.baidu.com'.$f;//Completion the url if($f[4]=='s')continue;//If the url is "https://" continue (the simple_html_dom might can't prase the https:// url) if(stripos($f,"baidu")==FALSE)continue;//If the url not in this website continue echo $f . '<br>'; $tmp[$cun++]=$f; //Save the urls into array } foreach($tmp as $r) //Dig the urls in $tmp[] { $html2=file_get_html($r); //Redo the step foreach($html2->find('a') as $a) { $u=$a->href; if($u[0]=='/')$u='http://www.baidu.com'.$u; if($u[4]=='s')continue; if(stripos($u,"baidu")==FALSE)continue; echo $u.'<br>'; } $html2=null; } ?>
登入後複製
//最後總會出現一個Fatal error: Call to a member function find() on a non-object in D:xampphtdocshtmlindex.php on line 21 的警告與學長溝通後改正了很多小錯誤不過這個仍然沒有解決希望有大神能夠指點一下
-------------------- -分割線--------------------
simple_html_dom下載:
https://github.com/Ph0enixxx/simple_html_dom
= =家裡電腦用不了git4win
以上就介紹了 php 自製基於simple_html_dom的爬蟲一隻v1.0,包含了方面的內容,希望對PHP教程有興趣的朋友有所幫助。
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
3 週前
By DDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
2 週前
By DDD
威爾R.E.P.O.有交叉遊戲嗎?
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)
