且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DOM解析器foreach

更新时间:2023-02-26 10:50:54

尝试这样:

$html = file_get_html('http://www.amazon.com/gp/offer-listing/B002UYSHMM');

$articles = array();

foreach($html->find('table tbody.result tr') as $article) {
  if($article->find('span.price', 0)) {
    // get retail
    $item['Retail'] = $article->find('span.price', 0)->plaintext;
    // get soldby
    if($article->find('img', 0)) $item['SoldBy'] = $article->find('img', 0)->getAttribute('alt');
    $articles[] = $item;
  }

}

print_r($articles);