我正在开发一个脚本来获取 PHP5 的 POO 中带有 cURL 的网站的一些元素,这是我的代码:
class obtain{
protected $url;
private $handler;
protected $response;
function __construct($url){
$this->url = $url;
}
protected function curl(){
$this->handler = curl_init($this->url);
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true);
$this->response = curl_exec($this->handler);
curl_close($this->handler);
return $this->response;
}
}
class page extends obtain{
private $reponse;
private $dom;
function __construct(){
parent::__construct('http://www.page.com');
$this->response = parent::curl();
$this->dom = new DOMDocument();
$this->dom = $this->dom->loadHTML($this->response);
var_dump($this->dom->getElementById('contenido-portada'));
}
}
new page();
运行时出现此错误:
致命错误:在...中的非对象上调用成员函数 getElementById()
为什么?
谢谢!