2012-03-15

CODE - 用 PHP Simple HTML DOM Parser 來抓網頁內容

利用 PHP Simple HTML DOM Parser 來抓網頁內容, 如下圖
抓所有在 
body -> container -> mainContent -> content -> .vol -> ul -> li 
href 路徑 (紅框部份)
include('./simple_html_dom.php');
$books = array();
$html = file_get_html($TARGET_PAGE);
$html = $html->getElementById('content');
foreach ($html->find('div.vol') as $ul) {
 foreach ($ul->find('li') as $li) {
  $bookUrl = HOST_NAME.$li->children(0)->href;
  array_push($books, $bookUrl);
 }
}



cf : 



1 則留言:

  1. part2 : http://trully622.blogspot.tw/2013/03/code-php-simple-html-dom-parser-part2.html

    回覆刪除