[英]Get HTML nodes that have the same parent - JAVA
I have a document containing several forms similar to the example posted below.我有一个包含多种表单的文档,类似于下面发布的示例。 I want to extract all the name/value pairs from the hidden input fields of one of the forms, the form is identified by its name and I don't know in advance how many hidden fields will be present.
我想从其中一个表单的隐藏输入字段中提取所有名称/值对,该表单由其名称标识,我事先不知道将存在多少个隐藏字段。
I am able to select all the relevant input fields in the document using the selector query: input[type=hidden][name][value]
我可以使用选择器查询选择文档中的所有相关输入字段:
input[type=hidden][name][value]
Is there a way to only select the input fields which has FORM[name=lgo]
as parent?有没有办法只选择具有
FORM[name=lgo]
作为父级的输入字段? Using some kind filter maybe?也许使用某种过滤器?
<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>
Based on this info , at least one of following should work -基于此信息,至少以下一项应该有效 -
doc.select("form[name=lgo] > input[type=hidden]");
Or, you can chain your selects -或者,您可以链接您的选择 -
doc.select("form[name=lgo]").select("input[type=hidden]");
The select method is available in a Document, Element, or in Elements.
select 方法在文档、元素或元素中可用。 It is contextual, so you can filter by selecting from a specific element, or by chaining select calls.
它是上下文相关的,因此您可以通过从特定元素中进行选择或通过链接选择调用来进行过滤。
<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.