Tôi đang cố gắng lấy các phần tử "liên kết" từ các trang web nhất định. Tôi không thể tìm ra những gì tôi đang làm sai mặc dù. Tôi nhận được lỗi sau:PHP DOMDocument :: loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: không có tên trong Entity
Severity: Warning
Message: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 536
Filename: controllers/test.php
Line Number: 34
Dòng 34 là sau trong mã:
$dom->loadHTML($html);
mã của tôi:
$url = "http://www.amazon.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
if($html = curl_exec($ch)){
// parse the html into a DOMDocument
$dom = new DOMDocument();
$dom->recover = true;
$dom->strictErrorChecking = false;
$dom->loadHTML($html);
$hrefs = $dom->getElementsByTagName('a');
echo "<pre>";
print_r($hrefs);
echo "</pre>";
curl_close($ch);
}else{
echo "The website could not be reached.";
}
Đã thay đổi thành url thân thiện với google. Hoàn nguyên nó trở lại nếu nó không thích hợp cho bạn .. –
Bạn có thấy điều này không? [why-would-does-this-error-handling-function-cause-domdocument-to-hang] (http://stackoverflow.com/questions/7129115) –