DOMDocument ::加载了很多警告

时间:2014-10-24 06:37:27

标签: php domdocument

我的问题是我的代码很小,错误很大。你能帮我解决这个问题吗? 我需要为学校做作业,我需要从整个网站www.asaphshop.nl获取一张图片 这是我的(小)代码:

<?php
$source = "http://www.asaphshop.nl";
$doc = new DOMDocument("");
$doc->load($source);
echo $doc->saveXML();

?>

这些都是我的错误:

Warning: DOMDocument::load(): error parsing attribute name in http://www.asaphshop.nl, line: 132 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): attributes construct error in http://www.asaphshop.nl, line: 132 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): Couldn't find end of Start Tag iLength line 132 in http://www.asaphshop.nl, line: 132 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): Opening and ending tag mismatch: input line 144 and script in http://www.asaphshop.nl, line: 152 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): Opening and ending tag mismatch: link line 232 and head in http://www.asaphshop.nl, line: 333 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): Entity 'nbsp' not defined in http://www.asaphshop.nl, line: 368 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): xmlParseEntityRef: no name in http://www.asaphshop.nl, line: 465 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): xmlParseEntityRef: no name in http://www.asaphshop.nl, line: 465 in C:\xampp\htdocs\stage\ripper3.php on line 4

Warning: DOMDocument::load(): Opening and ending tag mismatch: li line 652 and ul in http://www.asaphshop.nl, line: 661 in C:\xampp\htdocs\stage\ripper3.php on line 4

2 个答案:

答案 0 :(得分:0)

http://www.asaphshop.nl上的网页包含无效的HTML,因此DOMDocument无法对其进行解析。你的代码是正确的。 尝试使用另一个HTML解析器。

顺便说一下,有警告,而不是错误。您可以在php.ini设置中删除它们。

答案 1 :(得分:0)

这是因为http://www.asaphshop.nl的HTML无效。如果要打印这些警告,可以这样做:

$source = "http://www.asaphshop.nl";
$doc = new DOMDocument("");
@$doc->load($source);
echo $doc->saveXML();

如果您想修复HTML,可以在此处查看:PHP parsing invalid html