[英]java jsoup parse how to parse html
Is there any possible way to parse 有没有可能解析的方法
<a href="/summoner/userName=Huhi" class="Link">Huhi</a>
in html: 在html中:
<a href="/summoner/userName=Huhi" class="Link">Huhi</a>
<a href="/summoner/userName=Huhi" class="Link">White</a>
<a href="/summoner/userName=Huhi" class="Link">Angle</a>
Output: 输出:
Huhi
White
Angle
Create your document and get all the a[href] links, iterate through these links and get the text they contain. 创建您的文档并获取所有a [href]链接,遍历这些链接并获取其中包含的文本。 Like so:
像这样:
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("a[href]");
for (Element link : links) {
String text = link.text();
}
You just select a
and iterate the elements
and print 您只需选择
a
并迭代elements
并打印
String html ="<a href=\"/summoner/userName=Huhi\" class=\"Link\">Huhi</a>\n" +
"<a href=\"/summoner/userName=Huhi\" class=\"Link\">White</a>\n" +
"<a href=\"/summoner/userName=Huhi\" class=\"Link\">Angle</a>";
Document doc = Jsoup.parse(html);
Elements links = doc.select("a");
for (Element link : links) {
System.out.println(link.text());
}
For further reference check this link selector-syntax 有关更多参考,请检查此链接选择器语法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.