Jump to content

DOM Anchor Object Property


fpyontek

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.