我正在开发一个应用程序,显示黄金率并为此创建图表.
我找到一个网站定期向我提供这个黄金价格.我的问题是如何从html页面中提取这个特定的价值.
这是我需要提取的链接= http://www.todaysgoldrate.co.in/todays-gold-rate-in-pune/,这个html页面有以下标签和内容.
<p><em>10 gram gold Rate in pune = Rs.31150.00</em></p>
Run Code Online (Sandbox Code Playgroud)
这是我用于提取的代码,但我没有找到提取特定内容的方法.
public class URLExtractor {
private static class HTMLPaserCallBack extends HTMLEditorKit.ParserCallback {
private Set<String> urls;
public HTMLPaserCallBack() {
urls = new LinkedHashSet<String>();
}
public Set<String> getUrls() {
return urls;
}
@Override
public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) {
handleTag(t, a, pos);
}
@Override
public void handleStartTag(Tag t, MutableAttributeSet a, int pos) {
handleTag(t, a, pos);
}
private void handleTag(Tag t, MutableAttributeSet a, int pos) {
if (t == Tag.A) {
Object href = a.getAttribute(HTML.Attribute.HREF);
if (href != null) {
String url = href.toString();
if (!urls.contains(url)) {
urls.add(url);
}
}
}
}
}
public static void main(String[] args) throws IOException {
InputStream is = null;
try {
String u = "http://www.todaysgoldrate.co.in/todays-gold-rate-in-pune/";
//Here i need to extract this content by tag wise or content wise....
Run Code Online (Sandbox Code Playgroud)
提前致谢.......
| 归档时间: |
|
| 查看次数: |
9119 次 |
| 最近记录: |