此代码适用于站点a:
require('simple_html_dom.php');
$html = file_get_html('http://www.aaa.co.uk/Products/decking-screw-green');
echo $html;
foreach($html->find('div[id=produttabs]') as $xxx) {
echo $xxx;
}
在另一个网站上,我没有得到任何返回,所以我找到了以下代码:
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0'r'n"));
$context = stream_context_create($opts);
$html1 =file_get_contents('http://bbbb/0/p/FORSTCK126Z',false,$context);
echo $html1;
$ret = $html1->find('div[class=panel marBottom20]', 0);
echo 'ret ='.$ret;
两个echo都显示返回的页面,但在第二个代码中我得到:
致命错误:在/home/xxx/public_html/xxx/techy/getimages.php第28行非对象上调用成员函数find()
类'panel marBottom20'存在于$html1当我检查页面。
我有什么不明白的吗?
谢谢
file_get_contents返回一个字符串,因此它没有find方法。这个方法定义在'simple_html_dom.php'
My Bad.
我注意到我的错误通过复制和粘贴。我在第二个代码中使用file_get_contents而不是file_get_html。