2016-04-21 40 views
0
<table> 
        <tbody> 
I WANT it =>   <input type="hidden" name="prodCd_8801043014830" id="prodCd_8801043014830" value="8801043014830"> 
         <input type="hidden" name="itemCd_8801043014830" id="itemCd_8801043014830" value="001"> 
         <input type="hidden" name="categoryId_8801043014830" id="categoryId_8801043014830" value="C001001700010001"> 
         <input type="hidden" name="maxQty_8801043014830" id="maxQty_8801043014830" value="20"> 
         <input type="hidden" name="minQty_8801043014830" id="minQty_8801043014830" value="1"> 
         <tr> 
         <-- CONTENTS--> 
         </tr> 

I WANT it  =>  <input type="hidden" name="prodCd_8801043015738" id="prodCd_8801043015738" value="8801043015738"> 
         <input type="hidden" name="itemCd_8801043015738" id="itemCd_8801043015738" value="001"> 
         <input type="hidden" name="categoryId_8801043015738" id="categoryId_8801043015738" value="C001001700010004"> 
         <input type="hidden" name="maxQty_8801043015738" id="maxQty_8801043015738" value="31"> 
         <input type="hidden" name="minQty_8801043015738" id="minQty_8801043015738" value="1"> 
         <tr> 
         <-- CONTENTS--> 
         </tr> 

HI我想获取第一个元素和1 + 5n输入隐藏标记值。隐藏标签组TR标签和输入隐藏标签之间没有容器。如何通过标记获取元素+使用选择器的第5个值

我试图2ways但他们返回惟独第一个值

Document doc=Jsoup.connect("URL").timeout(5000).get(); 
a is integer value 

for(int a=0;a<10;a++){ 

int n = 0+5a 

1.Elements testattrval = 
doc.select("table tbody input[type=hidden]:eq("+n+")"); 

2.Elements testattrval = doc.select("table tbody input[type=hidden]:nth-child(+"n+")"); 

} 
+0

该HTML无效。你不能把输入元素放在你有的地方。 – Rob

+0

为什么不使用className或ID? – kiro112

+0

该HTML无效? 0_0我想学习HTML解析,所以我试着从互联网购物商场解析信息。 :(...在这个页面中,#productform(fomtag)有这个表格,我很乐意提供你的建议,我更喜欢:) http://www.lottemart.com/search/search.do?searchField= &searchTerm =%EA%B0%90%EC%9E%90&viewType = list – prepare123

回答

0

,用于通过物体的集合jQuery的迭代,你可以使用。每()方法错误的价值观。如果你特别希望每5个值,检查项目的索引是整除5

$("input[type='hidden']").each(function (index){ 
    if(index % 5 === 0){ 
     console.log($(this).val()); 
    } 
}); 

在这里,我记录的输入元素到控制台窗口的值。

+1

我很困惑。 OP要求提供Jsoup解决方案并接受jQuery答案... – luksch

+0

他最初标记为jQuery,但有人在发布此消息后更新了他的标记。我仍然困惑为什么这是公认的答案,因为它看起来像他想用jsoup。 – SeanOB

1

U可以简单地用jQuery做到像这个 -

$("input[type='hidden']:nth-child(5)"); 

要选择第5个元素。 更多可以找到here

相关问题