How to extract value form HTML section in PHP -
i need extract data html page looks like:
<li> <h2> <a href="/rss/football/actu_rss_35.xml" target="_blank" class="rss"><span>rss</span></a>ac ajaccio</h2> <div class="club-left"> <a href="/football/footballficheclub35.html" title="ac ajaccio"><img src="http://medias.lequipe.fr/logo-football/35/60?cch-13-40" width="60" height="60"></a> </div> <div class="club-right"> <ul class="club-links"> <li><span class="plus"></span> <a href="/football/footballficheclub35.html">fiche club </a> </li> <li><span class="plus"></span> <a href="/football/footballficheclub35.html#calendrier">calendrier</a> </li> <li><span class="plus"></span><a href="/football/footballficheclub35.html#effectif">effectif</a> </li> <li><span class="plus"></span> <a href="/football/footballficheclub35.html#joueurs">stats joueurs</a> </li> <li><span class="plus"></span> <a href="/football/footballficheclub35.html#statistiques">stats club</a> </li> </ul> </div> <div class="clubt hidden">35</div> <div class="clear"></div> </li>
i extract in php href value , text of part:
<a href="**/football/footballficheclub35.html#joueurs**">**stats joueurs**</a>
i use following code, there missing:
$elements = $xpath->query("//div[@id='base']/ul/li"); if (!is_null($elements)) { foreach ($elements $element) { $nodes = $element->childnodes; foreach ($nodes $node) { if($node->nodename!='#text'){ echo $node->nodevalue.";<br/>"; $stringdata = trim($node->nodevalue).";"; } } }
update:
try:
$elements = $xpath->query("//ul[@class='club-links']//a"); foreach ($elements $element) { echo $element->nodevalue." - ".$element->getattribute("href")."<br/>"; }
Comments
Post a Comment