0

Using the xPath, how can I get the data inside this tag ?

<a href="/poker/?ca=v"> THIS </a>

This is the source code, I do not know if there is a need of getting the tree though

<div id="nav">
        <ul id="someID">
            <li><a href="/poker/?ca=v"> THIS </a></li>
        </ul>
</div>

Thank you

UPDATE

here is my code

function extractNodeValue($query, $xPath, $attribute = null) {
    $node = $xPath->query("//{$query}")->item(0);
    if (!$node) {
        return null;
    }
    return $attribute ? $node->getAttribute($attribute) : $node->nodeValue;
}

$document = new DOMDocument();
$document->loadHTML($html);
$xPath = new DOMXpath($document);
$name = extractNodeValue('//*[@id="row1"]',$xPath);

echo $name;
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

1 Answers1

0

Query:

//a[href="/poker/?ca=v"]/text()

PHP:

$html = <<<EOF
  ... the html (can be even a snippet)...
EOF;

$doc = new DOMDocument();
$doc->loadHTML($html);

$selector = new DOMXPath($doc);
$query = '//a[href="/poker/?ca=v"]/text()';

foreach($selector->query($query) as $text) {
    echo $text->nodeValue;
}
hek2mgl
  • 152,036
  • 28
  • 249
  • 266