Java Html解析器提取特定数据? [英] Java Html parser to extract specific data?

查看:301
本文介绍了Java Html解析器提取特定数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似以下的html文件

I have a html file like the following

...
<span itemprop="A">234</span>
...
<span itemprop="B">690</span>
...

在此我要提取值为A和B.

你能建议任何可以轻松做到的java的html解析器库吗?

In this i want to extract values as A and B.
Can u suggest any html parser library for java that can do this easily?

推荐答案

我个人赞成 JSoup over JTidy 。它有类似CSS的选择器,文档更好,imho 。使用JSoup,您可以使用以下行轻松提取这些值:

Personally, I favour JSoup over JTidy. It has CSS-like selectors, and the documentation is much better, imho. With JSoup, you can easily extract those values with the following lines:

Document doc = Jsoup.connect("your_url").get();
Elements spans = doc.select("span[itemprop]");

for (Element span : spans) {
  System.out.println(span.text()); // will print 234 and 690
}

这篇关于Java Html解析器提取特定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆