[英]Get Links with simple html dom
我正試圖從網站上獲取鏈接。
“ http://www.perfumesclub.com/es/perfume/mujer/c/ ”
為此,在簡單的html Sun中使用“user-agent”。
但我得到這個錯誤..
Fatal error: Call to a member function find() on string in C:\Users\Desktop\www\funciones.php on line 448
這是我的代碼:
謝謝^^
$url = 'http://www.perfumesclub.com/es/perfume/mujer/c/';
$option = array(
'http' => array(
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
)
);
$context = stream_context_create($option);
$html = new simple_html_dom();
$html = file_get_contents ($url, false, $context);
$perfumes = $html->find('.imageProductDouble'); --> this is line 448
foreach($perfumes as $perfume) {
// Get the link
$enlaces = "http://www.perfumesclub.com" . $perfume->href;
echo $enlaces . "<br/>";
}
$html
是調用file_get_contents
后的字符串。 嘗試
$html = file_get_html($url);
或使用
$html = str_get_html($html);
在調用file_get_contents
。
將您的file_get_contents包裝在str_get_html函數中
// method 1
$html = new simple_html_dom();
$html->load( file_get_contents ($url, false, $context) );
// or method 2
$html = str_get_html( file_get_contents ($url, false, $context) );
你正在創建一個新的dom並將其分配給變量$ html,而不是讀取返回字符串並將其設置為$ html的url,從而覆蓋你的simple_html_dom實例,所以當你調用find方法時你有一個字符串而不是一個字符串賓語。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.