Xpath not behaving for me in parsing basic html

后端 未结 1 1484
时光说笑
时光说笑 2020-12-22 05:05

I am trying to parse some basic html using xpath and running into issues. The returned output is always empty using what I am reading the xpath docs to say works. Below is m

相关标签:
1条回答
  • 2020-12-22 05:56

    DOMXPath::query returns a DOMNodeList. When you are doing

    foreach($result as $e){
    

    you are iterating over the DOMElement items a DOMNodeList. DOMElement does not have an item() method. Only DOMNodeList has that. Try with

    foreach($result as $e){
        echo $e->nodeValue, PHP_EOL;
    }
    
    0 讨论(0)
提交回复
热议问题