[英]How to check the type of an HTML element using jsoup
Given a HTML code snippet, 给定一个HTML代码段,
<div align="right">...<div>
<p class="text2">abc</p>
I have used jsoup to fetch all elements with their attribute, align
set to right
. 我已经使用jsoup来获取所有具有其属性的元素,
align
设置为right
。 Now I want to select the next sibling which i do using, el.nextElementSibling()
现在我要选择我使用的下一个兄弟姐妹
el.nextElementSibling()
How do I verify that the next element is a p
HTML element with a class of text2
? 如何验证下一个元素是带有
text2
类的p
HTML元素? I am new to jsoup and I am learning as I code. 我是jsoup的新手,我正在学习代码。 Any help would be appreciated!
任何帮助,将不胜感激! Thanks!
谢谢!
Use Element#getTagName
, which gives you the name of the tag for that element. 使用
Element#getTagName
,它为您提供该元素的标签名称。 That same API page also gives you Element#classNames
and a couple of other ways to look at the class
attribute. 相同的API页面还为您提供
Element#classNames
以及其他几种查看class
属性的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.