0

I'm following a simplified version of the scraping tutorial by NetTuts here, which basically finds all divs with class=preview

http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/comment-page-1/#comments

This is my code. The problem is that when I count $items I get only 1, so it's getting only the first div with class=preview, not all of them.

$articles = array();   
$html = new simple_html_dom();
$html->load_file('http://net.tutsplus.com/page/76/');

$items = $html->find('div[class=preview]');  
echo "count: " . count($items);
4

1 に答える 1

1

DOMDocumentを使用してみてくださいDOMXPath

$file = file_get_contents('http://net.tutsplus.com/page/76/');
$dom = new DOMDocument();
@$dom->loadHTML($file);
$domx = new DOMXPath($dom);
$nodelist = $domx->evaluate("//div[@class='preview']");
foreach ($nodelist as $node) { print $node->nodeValue; }
于 2011-09-22T21:33:35.463 に答える