简体   繁体   English

Jsoup-从指定类下具有特定类的所有元素获取文本

[英]Jsoup - get text from all elements with a particular class under a Specified class

I have an HTML like, 我有一个类似的HTML,

<aside class="continfo">
<p>
  <span class="jtel"></span>
  <a class="tel" href="tel:+918041240281">+(91)-80-41240281</a>, 
  <a class="tel" href="tel:+918041240282">41240282</a>
</p>
</aside>

here there are two elements with 'tel' class, how can I extract both of these? 这里有'tel'类的两个元素,如何提取这两个元素? How can i extract if the number of these classes with the name 'tel' is not known by the program? 如果程序不知道这些名称为“ tel”的类的数量,该如何提取? Please help. 请帮忙。

The final Goal is to get all the text in the tel class elements. 最终目标是获取tel类元素中的所有文本。

I have tried working it out with next sibling element. 我试着用下一个兄弟元素解决它。 but no luck there. 但那里没有运气。 I might have tried it wrong though. 我可能尝试错了。 Please correct me or help me achieve what i am trying here. 请纠正我或帮助我实现我在这里所做的尝试。

Thanks in advance. 提前致谢。

Here you can found same samples: 在这里您可以找到相同的样本:

Elements links = doc.select("a.tel");
for (Element el: links) {
   String tel = el.attr("href"); //.If you want the href attr
   // String tel = el.text() if you want the inner text
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM