html dom在他们在那里时没有给出结果

时间:2015-02-05 02:09:23

标签: php curl simple-html-dom

我正在尝试获取该网页的标题,请参阅下面的代码。

include("simple_html_dom.php");
$url = "http://fzmoviez.in/video/list/4059539";

$base = $url;

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);

// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);
$title = $html_base->getElementsByTagName("title")->innertext; //line 21
echo $title;

我收到错误:

Notice: Trying to get property of non-object in C:\xampp\htdocs\... on line 21

但当我var_dump($html_base)时,我

object(simple_html_dom)#1 (23) { ["root"]=> object(simple...
    ... card" ["attr"]=> array(2) { ["id"]=> string(5) "index" ["title"]=> string(179) "FzMoviez.iN - Free Download Latest Bollywood Movies,Hindi Dudded Movies,Hollywood Movies,Live Movies,WWE Shows,Mp4,HD Mp4,High Quality Mp4,Avi,Iphone,Android,Tablets And Many More" } ["children"]=> array(25) { [0]=> object(simple_html_dom_node)#55 (9) { ["nodetype"]=>......

意思是, 它是一个对象 并且标题是 ,为什么会给出错误

Notice: Trying to get property of non-object in C:\xampp\htdocs\.. on line 21

1 个答案:

答案 0 :(得分:0)

$html_base->getElementsByTagName("title")
将返回元素数组,您需要遍历此数组以获取数据。