Sei sulla pagina 1di 3

1/20/2016 JsoupgettitlefromHTML|Tutorialspointexamples

Tutorialspointexamples
(http://tutorialspointexamples.com)
Learnjavatutorialwithexamplesforbeginnersonline

Search

JsoupGetTitleFromHTMLExample
LetusdiscusshowtogettitlefromHTMLusingJsoupAPIwiththehelpofbelowexample.

Followthebelowsteps:
1.Useconnect(Stringurl)methodofJsoupclasswhichreturnstheconnectionofspecifiedURL.
2.Useget()methodofConnectionclasswhichreturnsDocumentobject.
3.Usetitle()methodofDocumentclasstogetthetitle.
4.Printthetitle.

Example:
JsoupGetTitle.java

http://tutorialspointexamples.com/jsoupgettitlefromhtmlexample/ 1/6
1/20/2016 JsoupgettitlefromHTML|Tutorialspointexamples

importjava.io.IOException;
importorg.jsoup.Jsoup;
importorg.jsoup.nodes.Document;

/**
*ThisclassisusedgettitlefromHTMLusingJsoup.
*@authorjavawithease
*/
publicclassJsoupGetTitle{
publicstaticvoidmain(Stringargs[]){
Documentdocument;
try{
//GetDocumentobjectafterparsingthehtmlfromgivenurl.
document=Jsoup.connect("http://tutorialspointexamples.com/").get();

//Gettitlefromdocumentobject.
Stringtitle=document.title();

//Printtitle.
System.out.println("Title:"+title);
}catch(IOExceptione){
e.printStackTrace();
}
}
}

Output:
Title:Javawithease|Easyandstepbysteplearningofjava.

Downloadthisexample.(http://tutorialspointexamples.com/wp
content/uploads/2015/03/JsoupExample4.rar)

NextTopic:JsoupgetlinksfromHTMLexample.(http://tutorialspointexamples.com/jsoupget
linksfromhtmlexample/)
PreviousTopic:JsoupHTMLparsingfromURLexample.
(http://tutorialspointexamples.com/jsouphtmlparsingfromurlexample/)

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/)

http://tutorialspointexamples.com/jsoupgettitlefromhtmlexample/ 2/6
1/20/2016 JsoupgettitlefromHTML|Tutorialspointexamples

SendinlineimageinemailusingJavaMailAPI.(http://tutorialspointexamples.com/sendinlineimage
inemailusingjavamailapi/)
Quartz2JobListenerexample.(http://tutorialspointexamples.com/quartz2joblistenerexample/)

9 0 Share 7 Share 0 0 Share 0 0


0 Share 0 0

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/jsoupgettitlefromhtmlexample/ 3/6

Potrebbero piacerti anche