fpyontek Posted March 31, 2010 Share Posted March 31, 2010 I need to access the DOM Anchor Object Property while scraping an HTML file. I cannot find a reference to the text between the anchors, not the href but the "clickable" text which appears between the right and left carots. Here is an example of the Anchor. a href="http://cnj.craigslist.org/ctd/1668776815.html">1998 Pontiac Grand Prix GT - $3995</a> What I am having trouble retrieving is the text: 1998 Pontiac Grand Prix GT - $3995 Here is my code: <?php $dom = new domDocument; $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $anchors = $dom->getElementsByTagName('a'); foreach ($anchors as $anchor){ echo $anchor->getAttribute("href")."<br>"; echo $anchor->getAttribute("innerhtml")."<br>"; } ?> Thanks Link to comment https://forums.phpfreaks.com/topic/197103-dom-anchor-object-property/ Share on other sites More sharing options...
salathe Posted March 31, 2010 Share Posted March 31, 2010 You can use the $anchor->textContent property. Link to comment https://forums.phpfreaks.com/topic/197103-dom-anchor-object-property/#findComment-1034643 Share on other sites More sharing options...
fpyontek Posted April 1, 2010 Author Share Posted April 1, 2010 Thanks for your help, exactly what I needed. Fred Link to comment https://forums.phpfreaks.com/topic/197103-dom-anchor-object-property/#findComment-1035046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.