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
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pankaj Kumar Yadav
Pankaj has been working as a Grails developer expertise in struts, spring, ejb, hibernate and angularjs framework.