Php Dom文档结果错误

Php Dom文档结果错误,php,domdocument,Php,Domdocument,我想从html中提取一些元素,但我无法根据需要提取数据 html 2015年11月3日09:29这是文章的标题 $dom=新的DOMDocument(); $classname=‘意见’; $html=获取页面($url); @$dom->loadHTML($html); $dom->preserveWhiteSpace=false; $xpath=newdomxpath($dom); $articles=$xpath->query(“/*[@class=”)“$classname

我想从html中提取一些元素,但我无法根据需要提取数据

html


  • 2015年11月3日09:29这是文章的标题

$dom=新的DOMDocument(); $classname=‘意见’; $html=获取页面($url); @$dom->loadHTML($html); $dom->preserveWhiteSpace=false; $xpath=newdomxpath($dom); $articles=$xpath->query(“/*[@class=”)“$classname.”“]”; $p=$articles->getElementsByTagName('a'); $div=$articles->getElementsByTagName('div'); foreach(p为$value){ $title=$value->getAttribute(“href”); echo$标题; }
当我运行这个脚本时,我得到一个错误“调用未定义的方法DOMNodeList::getElementsByTagName()


我真正需要的是,我需要每个href链接和img src路径(如果有)以及这个的span text值。请提出你的建议如何实现这一点。

也许你可以从我的建议中学到一些东西

或者,如果您决定包含我的函数,以下是我的操作方式:

    $html = ""; //your html
    $props = array(
    array("tagname"=>"div", "props"=>array("class"=>"opinions")),
    //the '/' before 'a' is for all descendant <a> of <div>
    array("tagname"=>"/a"),
    );
    $options = array("property"=>"href");
    require_once 'getNodeValue.php';
    $hrefs = getNodeValue($html, $props, $options);
    print_r($hrefs);
$html=”“//你的html
$props=阵列(
数组(“标记名”=>“div”,“道具”=>数组(“类”=>“意见”),
//“a”之前的“/”表示
数组(“标记名”=>“/a”),
);
$options=array(“属性”=>“href”);
需要一次“getNodeValue.php”;
$hrefs=getNodeValue($html、$props、$options);
印刷费($hrefs);
    $html = ""; //your html
    $props = array(
    array("tagname"=>"div", "props"=>array("class"=>"opinions")),
    //the '/' before 'a' is for all descendant <a> of <div>
    array("tagname"=>"/a"),
    );
    $options = array("property"=>"href");
    require_once 'getNodeValue.php';
    $hrefs = getNodeValue($html, $props, $options);
    print_r($hrefs);