Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用简单的HTMLDOM获取链接_Php_Html_Find_File Get Contents_Simple Html Dom - Fatal编程技术网

Php 使用简单的HTMLDOM获取链接

Php 使用简单的HTMLDOM获取链接,php,html,find,file-get-contents,simple-html-dom,Php,Html,Find,File Get Contents,Simple Html Dom,我正在尝试从该站点获取链接 “” 为此,请在简单html Sun中使用“用户代理” 但是我得到了这个错误 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(

我正在尝试从该站点获取链接

“”

为此,请在简单html Sun中使用“用户代理”

但是我得到了这个错误

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/>";
}
$url='1!'http://www.perfumesclub.com/es/perfume/mujer/c/';
$option=array(
“http'=>数组(
'方法'=>'获取',
'header'=>'用户代理:Mozilla/5.0(兼容;Googlebot/2.1+http://www.google.com/bot.html)',
)
);
$context=stream\u context\u create($option);
$html=新的简单html\U dom();
$html=file\u get\u contents($url,false,$context);
$perfumes=$html->find('.imageProductDouble');-->这是448号线
foreach($香水作为$香水){
//获取链接
$enlaces=”http://www.perfumesclub.com“$香水->href;
echo$enlaces.“
”; }
$html
是调用
文件获取内容后的字符串。试一试

$html = file_get_html($url);
或使用

$html = str_get_html($html);

调用
file\u get\u contents

后,将文件内容包装到str\u get\u 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,而不是读取返回字符串的url并将其设置为$html,从而覆盖简单的\u html\u dom实例,因此在调用find方法时,您拥有一个字符串而不是一个对象。

这是真的。我没有想到。非常感谢你。