Sto sviluppando un'applicazione che mostra la frequenza dell'oro e crea un grafico per questo.
Trovo uno website che mi fornisce regolarmente questa tariffa oro. La mia domanda è come estrarre questo valore specifico dalla pagina html.
Ecco il collegamento che ho bisogno di estrarre = http://www.todaysgoldrate.co.in/todays-gold-rate-in-pune/ e questa pagina html ha il seguente tag e contenuto.Come ottenere un valore specifico da html in java?
<p><em>10 gram gold Rate in pune = Rs.31150.00</em></p>
Ecco il mio codice che uso per l'estrazione, ma non ho trovato modo per estrarre contenuto specifico.
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....
Grazie in anticipo .......
Grazie uomo .... ottengo quello che voglio ... continuate così! –
Prego :) – Pratik