Skip to main content

Posts

Showing posts with the label Data Extraction

How to parse HTML/ extract data from HTML / using Java?

Java has a large set of APIs to parse HTML. To extract data from HTML  and perform any manipulation we should be able to parse it. jsoup provides a very easy to use , powerful and compact API to pare HTML and extract data. It supports DOM, CSS and jquery like selectors. It is designed for all types of HTML and will even parse HTML which is not perfectly valid. Example In this example we fetch BBC Sport , parse it to DOM and then select headlines using css-selector. Document doc = soup.connect(" http://www.bbc.co.uk/sport/0/ ").get();  Elements newsHeadlines = doc.select("#more-news-headlines li"); We can also provide HTML directly in a string.  A detailed documentation is available at jsoup website. You may start from official cook book available here .