Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Tutorialspointexamples
(http://tutorialspointexamples.com)
Learnjavatutorialwithexamplesforbeginnersonline
Search
JsoupHTMLParsingFromStringExample
LetusdiscusshowtoparseHTMLfromstringusingJsoupAPIwiththehelpofbelowexample.
Followthebelowsteps:
1.DefineHTMLasastring.
2.Useparse(Stringhtml)methodofJsoupclasswhichreturnsDocumentobjectafterprocessingthehtml
string.
3.Usetitle()methodofDocumentclasstogetthetitle.
4.Printthetitle.
Example:
JsoupParseHTMLFromString.java
http://tutorialspointexamples.com/jsouphtmlparsingfromstringexample/ 1/6
1/20/2016 jsouphtmlparsefromstring|Tutorialspointexamples
importorg.jsoup.Jsoup;
importorg.jsoup.nodes.Document;
/**
*ThisclassisusedforHTMLparsingfromStringusingJsoup.
*@authorjavawithease
*/
publicclassJsoupParseHTMLFromString{
publicstaticvoidmain(Stringargs[]){
//DefineHTMLasastring.
StringhtmlString="<html><head><title>JsoupStringHTMLTest"+
"</title></head><body><p>ParsedHTMLfromString."+
"</p></body></html>";
//GetDocumentobjectafterparsingthehtmlstring.
Documentdocument=Jsoup.parse(htmlString);
//Gettitlefromdocumentobject.
Stringtitle=document.title();
//Printtitle.
System.out.println("Title:"+title);
}
}
Output:
Title:JsoupStringHTMLTest
Downloadthisexample.(http://tutorialspointexamples.com/wp
content/uploads/2015/03/JsoupExample1.rar)
NextTopic:Jsoupoverview.(http://tutorialspointexamples.com/jsoupoverview/)
PreviousTopic:JsoupHTMLparsingfromfileexample.(http://tutorialspointexamples.com/jsoup
htmlparsingfromfileexample/)
RelatedTopics:
Howtobuildjavaprojectusingantineclipse?(http://tutorialspointexamples.com/howtobuildjava
projectusingantineclipse/)
JAXBmarshallingconvertjavaobjecttoxmlexample.(http://tutorialspointexamples.com/jaxb
marshallingconvertjavaobjecttoxmlexampleusingonepojo/)
HowtocreatepdffileinjavausingiTextjar?(http://tutorialspointexamples.com/howtocreatepdffile
injavausingitextjar/)
Genericsclassexample.(http://tutorialspointexamples.com/genericsclassexample/)
OGNLinstruts2.(http://tutorialspointexamples.com/ognlinstruts2/)
HibernateOnetoOneMappingusingxml.(http://tutorialspointexamples.com/hibernateonetoone
mappingusingxml/)
SendinlineimageinemailusingJavaMailAPI.(http://tutorialspointexamples.com/sendinlineimage
inemailusingjavamailapi/)
http://tutorialspointexamples.com/jsouphtmlparsingfromstringexample/ 2/6
1/20/2016 jsouphtmlparsefromstring|Tutorialspointexamples
Quartz2JobListenerexample.(http://tutorialspointexamples.com/quartz2joblistenerexample/)
Jsoup Tutorial
Jsoupoverview.(http://tutorialspointexamples.com/jsoupoverview/)
HTMLparsingfromstring.(http://tutorialspointexamples.com/jsouphtmlparsingfromstringexample/)
HTMLparsingfromfile.(http://tutorialspointexamples.com/jsouphtmlparsingfromfileexample/)
HTMLparsingfromURL.(http://tutorialspointexamples.com/jsouphtmlparsingfromurlexample/)
GettitlefromHTML.(http://tutorialspointexamples.com/jsoupgettitlefromhtmlexample/)
GetlinksfromHTML.(http://tutorialspointexamples.com/jsoupgetlinksfromhtmlexample/)
GetimagesfromHTML.(http://tutorialspointexamples.com/jsoupgetimagesfromhtmlexample/)
GetmetadatafromHTML.(http://tutorialspointexamples.com/jsoupgetmetadatafromhtmlexample/)
Getformparameters.(http://tutorialspointexamples.com/jsoupgetformparametersexample/)
http://tutorialspointexamples.com/jsouphtmlparsingfromstringexample/ 3/6