xml - PHP - parse webpage using SimpleXMLElement -


i have webpage i'm trying parse using simplexmlelement a#href "#3" , content of following span->a "jim":

<?xml version='1.0'?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     <head>..</head>     <title>this title<title>     <body>       <script>...</script>       <div id="div1">               </div>       <div id="content">         <div id="src">             <pre>                 <a name="1" href="#1">1</a>                 <span class="myclass">                     <a href="somelink123">john</a>                 </span>                 <a name="1" href="#2">2</a>                 <span class="myclass">                     <a href="somelink2342">dev</a>                 </span>                 <a name="1" href="#3">3</a>                 <span class="myclass">                     <a href="somelink33452">jim</a>                 </span>                 ....                 ....             </pre>         </div>       </div>    </body> </html> 

i'm using simplexmlelement children of 'pre' how access elements based on attributes , siblings?

thanks!

use php domdocument

this code a#href "#3" , find span next it.

$dom = new domdocument(); libxml_use_internal_errors(true);//disable libxml errors $dom->loadhtmlfile("test.html");//saved html test.html  $xpath = new domxpath($dom);  $spanval = $xpath->query("//a[@href='#3']/following-sibling::*[1]");  foreach($spanval $span) {     echo $span->nodevalue; } 

output:

jim  

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -