0
这让我陷入了一段时间,所以我想我会发布它。我的问题是,我find->不正常工作和$ PRODUCT_NAME就要到了空PHP简单DOM找不到工作
require 'mysql_con.php';
require 'simple_html_dom.php';
$html = file_get_html('http://www.xxxx.com/index.php?main_page=index&cPath=23');
/* foreach($html->find('img') as $element) {
echo $element->src . '<br>';
} */
$find = $html->find('#specialsListing .specialsListBoxContents .indent a');
$i=0;
foreach ($find as $test) {
$link = html_entity_decode($test->href);
$linkgrab = file_get_html($link);
$product_name = $linkgrab->find('#productName')->innertext;
echo $product_name;
break;
}
find方法返回一个对象数组。如果你指定第二个参数(在你的情况下为'0'),那么它返回数组中该键的对象。它在文档http://simplehtmldom.sourceforge.net/manual_api.htm innertext中没有为数组设置,而是针对单个对象。 – 2013-05-02 23:41:07