我想从网站上提取电话号码,但最后我收到了错误消息。
Error: Notice: Trying to get property of non-object in C:\xampp\htdocs\testing.php on line 15
我的代码如下:
$ch=curl_init("http://www.mudah.my/LG+G+Pro+2+D838+16GB+5+9in+2+26GHz+3GB+RAM+NEW+SET-30256077.htm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($cl);
$xpath = new DOMXpath($dom);
$phoneNo = $xpath->query("//div[@class='contact-phoneno']/text()");
$phone = $phoneNo->item(0)->nodeValue;
echo $phone;
答案 0 :(得分:0)
使用:
$phoneNo = $xpath->query("//div[@class='contact-phoneno']");
$phone = $phoneNo->item(0)->textContent;
我获得了:013611xxxx