I would like to extract the value of the attribute "value" using the id tag.
My code:
<?php
$url = 'http://turni.tt-contact.com/Default.aspx';
$contents = htmlentities(file_get_contents($url));
echo $contents."
"; //html
$dom = new DOMDocument;
$dom->validateOnParse = true;
$dom->loadHTML($contents);
$dom->preserveWhiteSpace = false;
$data = $dom->getElementById("__VIEWSTATE");
echo $data->nodeValue;
?>
I would like the attribute "value" -> "THIS":
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="THIS">
but the code returns only the html code.
What do I need to change?
Also by modifying it to:
$xpath = new DOMXpath($dom);
$data = $xpath->query('//input[@id="__VIEWSTATE"]');
$node = $data->item(0);
echo $node->getAttribute('value');
I get this error:
Fatal error: Call to a member function getAttribute() on null