本文介绍了Jsoup获取类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用解析元素
Elements input1 = pageListingParsed.select("form[name=MailForm] textarea");
示例输出为:
<textarea name="dec13d35885064571998cc1c81facc28" rows="5" wrap="virtual" class="form-control c-545599b92f2d2b5a09f21c06d490e810"></textarea>
如何获取课程名称?在这种情况下,我需要将c-545599b92f2d2b5a09f21c06d490e810
分配给变量.
How can I get the class names? In that case I would need to assign the c-545599b92f2d2b5a09f21c06d490e810
to a variable.
谢谢
推荐答案
如果确定元素大小为1,则需要获取第一个Element并对其使用方法attr(...)
:
if you are sure the element size is 1, then you need to get the first Element and use method attr(...)
for it:
Element e = input1.get(0);
System.out.println(e.attr("class"));
输出将是:
仅获得第二部分,您可以在其上简单地使用String.split(regex)
方法.
to only get the second part, you can simply use String.split(regex)
method on it.
例如
String s = "form-control c-545599b92f2d2b5a09f21c06d490e810";
System.out.println(s.contain(" ")? s.split(" ")[1] : s);
输出:
这篇关于Jsoup获取类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!