innerHTML in xPath?

后端 未结 4 513
醉话见心
醉话见心 2021-01-14 17:33

Is there a way of retrieving HTML (and JavaScript) contained in a div element?

4条回答
  •  终归单人心
    2021-01-14 17:54

    This will give you the outerHTML rather than the innerHTML, but you can easily strip the extra DIV tags at both ends.

    Working example:

    $xpath = new DOMXPath( @DOMDocument::loadHTML($the_html_code) ) ;
    $domElement = $xpath->evaluate("//div[@id='ID_of_the_div']")->item(0) ;
    $outerHTML = $domElement->ownerDocument->saveXML($domElement) ;
    

提交回复
热议问题