Parsing Html using Jsoup

Posted By : Pankaj Kumar Yadav | 22-Jun-2015

Parsing HTML using Jsoup

In this blog we will know that how to parse html using jsoup library.
 Here are the steps:- 

Step-1. Download jsop jar file from http://jsoup.org/download and add it in your grails/java project.
Step-2. use following code to parse html

 
String url = 'www.surveymyapp.com' // html file url
def htmlPage = Jsoup.connect(url).get() // parse html from url


Step-3. Now we can call different method of jsoup to get data
for example - 
To get data by div name 'divName'

def divData = htmlPage.select("div.divName").first().toString().text() 

To get image source 'logo'

 

 def imageSrc = detailsInfo.select("img.logo").attr("src")


To know more about jsoup visit  https://github.com/jhy/jsoup/    and    http://jsoup.org/

THANKS

 

About Author

Author Image
Pankaj Kumar Yadav

Pankaj has been working as a Grails developer expertise in struts, spring, ejb, hibernate and angularjs framework.

Request for Proposal

Name is required

Comment is required

Sending message..