Re: [請益] php 抓 google 搜尋結果特定區塊

看板PHP作者 (每天都在公司玩OLG)時間15年前 (2010/03/05 03:19), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《upp818 (KT)》之銘言: : 那應該要取 <div> ~~ </div> 還是 <li > ~~ </li> 呢? 你要取的是 <li> 。 : 而在取出某段 html 時,也遇到了一點問題 @@ 不用這麼辛苦的用 regular expression,有現成的可以用: http://simplehtmldom.sourceforge.net/index.htm API 參考文件: http://simplehtmldom.sourceforge.net/manual_api.htm 範例: <?php require_once('simple_html_dom.php'); $html = file_get_html('http://www.google.com.tw/search?q=php'); $li_arr = $html->find('.g'); foreach($li_arr as $li) { $link = $li->children(0)->children(0)->getAttribute('href'); $text = strip_tags($li->children(0)->children(0)->innertext); echo "<a href='$link'>$text</a><br />"; } ?> -- ╥╥╖╓─╥╖ ╓─╥╖╓╖ ╓─╥╖ ╓─╥╖ ╓╖╓╖ ╟╢ ╟╢ ╙╜ ╟╢╟╢ ╟╢ ║║╟╢ ╟╢ ╟╢ ╟─ ╟─╫╢ ╟╢ ╟─╫╜ ║║╟╢ ╟╢ ╟╢ ╓╖ ╟╢╟╢ ║║╟╢ ╨╜ ╙─╨╜ ╙─╨╜ ╙╜ ╙─╨╜╙╜ ╙╙╨╜ 獅子男 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.131.225
文章代碼(AID): #1Ba0Usm- (PHP)
文章代碼(AID): #1Ba0Usm- (PHP)