div类无效的file_get_contents

时间:2012-09-09 04:42:13

标签: php dom

我想使用此代码

根据div。我的类提取url中的数据
<?php
$doc = new DomDocument;
$doc->Load('http://placement.freshersworld.com/placement-papers/3i-Infotech/Placement-  Paper-Whole-Testpaper-18433/');
$doc->getElementsByClassName('company-contentdetailes');

echo $doc;
?>

但我没有得到什么作为输出。我想使用数组以及在一个页面可能有3-4个类,我想提取类公司的所有数据 - contentdetailes

执行此脚本时,我的错误日志中出现了很多错误

[09-Sep-2012 04:55:45 UTC] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Opening and ending tag mismatch: link line 143 and head in http://placement.freshersworld.com/placement-papers/3i-Infotech/Placement-Paper-Whole-Testpaper-18433/, line: 144 in /home/xxxxxxxxx/xxxxxx/test3.php on line 3
[09-Sep-2012 04:55:46 UTC] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: EntityRef: expecting ';' in http://placement.freshersworld.com/placement-papers/3i-Infotech/Placement-Paper-Whole-Testpaper-18433/, line: 236 in /home/xxxxxxxxxx/xxxxxxx/test3.php on line 3
[09-Sep-2012 04:55:46 UTC] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: EntityRef: expecting ';' in http://placement.freshersworld.com/placement-papers/3i-Infotech/Placement-Paper-Whole-Testpaper-18433/, line: 236 in /home/xxxxxxxxxx/test3.php on line 3
[09-Sep-2012 04:55:46 UTC] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: EntityRef: expecting ';' in http://placement.freshersworld.com/placement-papers/3i-Infotech/Placement-Paper-Whole-Testpaper-18433/, line: 236 in /

等......

2 个答案:

答案 0 :(得分:1)

  1. getElementByClassName不是真正的DOM方法。方法名称为getElementsByClassName(注意“元素”上的“s”)。

  2. getElementsByClassName不会修改传入的DOM对象;它返回一组匹配的DOM元素。你必须对这个集合做一些事情(在这种情况下,可能会循环并打印结果)。

答案 1 :(得分:0)

该文档不是有效的XML,有几个&amp;需要编码为&amp;以及未封闭的元元素。