-1

I have downloaded the Java HtmlParser but I dont know how to use the API for extracting the HTML data. Can you give some example so that I can work on it?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Vipul
  • 2,637
  • 6
  • 25
  • 28
  • Please start by stating *which* java html parser you are using. – Kirk Woll Aug 05 '10 at 14:59
  • Which HTML Parser you downloaded? – del.ave Aug 05 '10 at 14:59
  • Are you talking about *this* parser: http://htmlparser.sourceforge.net/ They have a "Samples" page: maybe what you're looking for is there: http://htmlparser.sourceforge.net/samples.html – FrustratedWithFormsDesigner Aug 05 '10 at 15:03
  • There are infinitely many possible examples, so this question could have infinitely many correct answers. This question is therefore _Too Broad_. What **precisely** do you not understand about how to use the API? – Raedwald Mar 10 '16 at 13:04

1 Answers1

2

You're talking about HtmlParser? Rather pick a parser with less verbose API like Jsoup. All you need to learn are then CSS selectors which are already obvious enough to the average frontend developer.

Here's a kickoff example which displays your current question and the names of all answerers:

package com.stackoverflow.q3416036;

import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Test {

    public static void main(String[] args) throws Exception {
        URL url = new URL("https://stackoverflow.com/questions/3416036");
        Document document = Jsoup.parse(url, 3000);

        String question = document.select("#question .post-text").text();
        System.out.println("Question: " + question);

        Elements answerers = document.select("#answers .user-details a");
        for (Element answerer : answerers) {
            System.out.println("Answerer: " + answerer.text());
        }
    }

}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555