我在這裏找不到任何東西或谷歌有關解析隱藏的輸入值。比如這段代碼就在這裏。我正試圖解析40個字符的鍵。如何解析隱藏的輸入值
<input type="hidden" name="key" value="c126b4f134cb2c1184c1585fdfa4d1b0013a12f4">
我試過這個,但它永遠不會返回任何隱藏的值。
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);
更新代碼
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');
var_dump($val);
返回此錯誤參照線 「$ VAL = $節點 - >的getAttribute( '值');」
Fatal error: Call to undefined method DOMNodeList::getAttribute()
XPath返回的NodeList作爲它的結果,而不是一個節點。改爲使用'$ nodes [0] - > getAttribute()'。 – 2011-03-19 02:56:53