[英]Get HTML nodes that have the same parent - JAVA
我有一个包含多种表单的文档,类似于下面发布的示例。 我想从其中一个表单的隐藏输入字段中提取所有名称/值对,该表单由其名称标识,我事先不知道将存在多少个隐藏字段。
我可以使用选择器查询选择文档中的所有相关输入字段: input[type=hidden][name][value]
有没有办法只选择具有FORM[name=lgo]
作为父级的输入字段? 也许使用某种过滤器?
<FORM METHOD='POST' onSubmit='javascript:isWaitForm();' ACTION='https://abc-azerty.querty.se/carmon/servlet/action/change_1 ' name='lgo'>
<input type='hidden' name='LogInFlag' value='1'>
<input type='hidden' name='LogInTime' value='2011-07-26 11:10'>
<input type='hidden' name='cCode2' value='SE'>
<a href='javascript:isWaitForm();javascript:document.lgo.submit();' class='linkNone'>Business Monitor</a>
<a href='javascript:isWaitForm();javascript:document.lgo.submit();' class='linkNone'>
<input type='image' src='/images/button_arrow_right.gif' height=19 width=22 border=0 style='float:left;'></A>
</FORM>
基于此信息,至少以下一项应该有效 -
doc.select("form[name=lgo] > input[type=hidden]");
或者,您可以链接您的选择 -
doc.select("form[name=lgo]").select("input[type=hidden]");
select 方法在文档、元素或元素中可用。 它是上下文相关的,因此您可以通过从特定元素中进行选择或通过链接选择调用来进行过滤。
<script type="text/javascript">
var inputs = document.getElementsByName('lgo')[0].getElementsByTagName('input');
for(var i = 0 ; i < inputs.length ; i++){
if(inputs[i].getAttribute('type') == "hidden") {
// This will get the name: inputs[i].getAttribute('name')
// This will get the value: inputs[i].value)
console.log(inputs[i].getAttribute('name') + ": " + inputs[i].value);
}}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.