jsoup多元素输出 [英] jsoup multi element output
问题描述
大家好,我尝试同时打印两个元素数据的输出
hello guys i am try to print the output of two element data simultaneously
Document document2 = Jsoup.parse(webPage2);
Document document22 = Jsoup.parse(webPage2);
Elements links2 = document2.select("a.yschttl");
Elements links22 = document22.select("div.abstr");
我们可以同时包含a.yschttl和div.abstr还是...
can we include both a.yschttl and div.abstr or...
for (Element link2 : links2) {
out.println(link2);
}
我们可以在for循环中同时包含两个say链接2和links22吗? 或如何达到目标...
can we include two say links2 and links22 in same for loop... or how to achive it...
推荐答案
如果您只是想同时选择两者,则可以执行以下操作:
If you are just trying to select both at the same time, you can do something like this:
for (Element link : document.select("a.yschttl, div.abstr") {
out.println(link);
}
如果您要进行两个选择并一并输出这些值,则必须执行类似@vacuum建议的操作,但要注意列表的长度.
If you are trying to make two selections and outputting those values in tandem, you will have to do something like @vacuum suggests, but being careful of the lengths of the lists.
一个旁注,您不必两次分析文档即可进行两个选择.您可以解析一次,然后选择两次.
A side note, you don't have to parse the document twice to make two selections. You can parse once and select twice.
这篇关于jsoup多元素输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!