如何解析隐藏的输入值 [英] how to parse an input value thats hidden

查看:77
本文介绍了如何解析隐藏的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里或Google上找不到与解析隐藏的输入值相关的任何内容.例如,此处的这段代码.我正在尝试解析40个字符的密钥.

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);

更新代码

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 = $ nodes-> getAttribute('value');"返回此错误.

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="">

因此,XPath当然会返回NULL-这就是存储在value属性中的内容:什么都没有.

so of course the XPath will return a NULL - that's what's stored in that value attribute: nothing.

这篇关于如何解析隐藏的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆