I can't find anything on here or google related to parsing input values that are hidden. For example this piece of code here. I am trying to parse the 40 character key.
<input type="hidden" name="key" value="c126b4f134cb2c1184c1585fdfa4d1b0013a12f4">
i tried this but it never returns the value of anything hidden.
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
$dom->loadHTMLFile('http://www6.cbox.ws/box/?boxid=524970&boxtag=7xpsk7&sec=form');
libxml_clear_errors();
$xp = new DOMXpath($dom);
$nodes = $xp->query('//input/@value');
foreach($nodes as $node)
{
echo( $node->textContent . "<br><br>" );
}
var_dump($node);
update code
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
$dom->loadHTMLFile('http://www6.cbox.ws/box/?boxid=524970&boxtag=7xpsk7&sec=form');
libxml_clear_errors();
$xp = new DOMXpath($dom);
$nodes = $xp->query('//input[type="hidden"]');
$val = $nodes->getAttribute('value');
v开发者_开发知识库ar_dump($val);
returns this error referring to line "$val = $nodes->getAttribute('value');"
Fatal error: Call to undefined method DOMNodeList::getAttribute()
$nodes = $xp->query('//input[type="hidden"]');
foreach ($nodes as $node) {
$val = $node->getAttribute('value');
}
comment followup:
If you look at the source of the page you've included in your code sample, you'll see there's only a single hidden form field, and it's got an empty value:
<input type="hidden" name="key" value="">
so of course the XPath will return a NULL - that's what's stored in that value attribute: nothing.
Using your update code, the fixed version would be:
<?php
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
// This link is now dead...
$dom->loadHTMLFile('http://www6.cbox.ws/box/?boxid=524970&boxtag=7xpsk7&sec=form');
libxml_clear_errors();
$val = array(); // Must be set before foreach loop
$xp = new DOMXpath($dom);
$nodes = $xp->query('//input[type="hidden"]');
foreach ($nodes as $node) {
$val[] = $node->getAttribute('value');
}
var_dump($val);
?>
精彩评论