From: Bruce F. <Bru...@sa...> - 2004-09-01 15:05:09
|
In the current code for HtmlUnit (i.e. the 1.3 pre-release code), the = getAnchors() method of the HtmlPage object does indeed return a list of = HtmlAnchor objects. The following code snippet was used to yield the results below: List anchorList =3D page.getAnchors(); for (Iterator iter =3D anchorList.iterator(); iter.hasNext();) { HtmlAnchor anchor =3D (HtmlAnchor) iter.next(); System.out.println("text: " + anchor.asText()); =09 System.out.println("href attribute: " + anchor.getHrefAttribute()); } text: some link name href attribute: somelink text: some link name 1 href attribute: somelink1 text: some link name 2 href attribute: somelink2 where the input HTML page looked like: <html> <body> <a href=3D"somelink">some link name</a> <a href=3D"somelink1">some link name 1</a> <a href=3D"somelink2">some link name 2</a> </body> </html> Hope this helps, Bruce -- Bruce Faulkner SAS Institute Inc. -----Original Message----- From: htm...@li... = [mailto:htm...@li...] On Behalf Of Robert = Baccus Sent: Wednesday, September 01, 2004 10:28 AM To: htm...@li... Subject: RE: [Htmlunit-user] Getting all the Anchor (HTMLLinks) on a = page? Actually looking at the code below only returns the Anchor objects not = the HtmlAnchor objects. I already looked at this and it didn't work for = me. I am not sure that the HtmlLink object is what I am looking for either = since I am trying to get the following <href a=3D"somelink">some link = name</a> in an object. I want to capture the Somelink and SomeLinkName = fields and put them in a list. Thanks. --- Bruce Faulkner <Bru...@sa...> wrote: > And, of course, if you really wanted the HtmlAnchor objects rather=20 > than the HtmlLink objects, then it is even easier: >=20 > List anchorList =3D myPage.getAnchors(); >=20 > Bruce > -- > Bruce Faulkner > SAS Institute Inc. >=20 > -----Original Message----- > From: htm...@li... > [mailto:htm...@li...] On Behalf Of Bruce=20 > Faulkner > Sent: Wednesday, September 01, 2004 8:23 AM > To: htm...@li... > Subject: RE: [Htmlunit-user] Getting all the Anchor (HTMLLinks) on a = page? >=20 >=20 > Something like the following code should give what you need: >=20 > List linkList =3D=20 > = myPage.getDocumentElement().getHtmlElementsByTagName(HtmlLink.TAG_NAME); > Where myPage is an instance of an HtmlPage. >=20 > Bruce > -- > Bruce Faulkner > SAS Institute Inc. > -----Original Message----- > From: htm...@li... > [mailto:htm...@li...] On Behalf Of Robert = > Baccus > Sent: Tuesday, August 31, 2004 8:13 PM > To: htm...@li... > Subject: [Htmlunit-user] Getting all the Anchor (HTMLLinks) on a page? >=20 >=20 > I noticed that HTMLUnit has the HtmlPage.getFirstAnchorByText(String=20 > text) method. But what I am trying to accomplish is to parse the=20 > whole page and pull out all of the HTMLLinks and put them into a list. = =20 > Can this easily be done? >=20 > Thanks. >=20 > =3D=3D=3D=3D=3D > Rob Baccus > Email: rb...@go... >=20 >=20 > =09 > __________________________________ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard.=20 > http://promotions.yahoo.com/new_mail >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today.=20 > http://ads.osdn.com/?ad_id=3D5047&alloc_id=3D10808&op=3Dclick > _______________________________________________ > Htmlunit-user mailing list Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today.=20 > http://ads.osdn.com/?ad_idP47&alloc_id=10808&op=3Dick > _______________________________________________ > Htmlunit-user mailing list Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today.=20 > http://ads.osdn.com/?ad_idP47&alloc_id=10808&op=3Dclick > _______________________________________________ > Htmlunit-user mailing list Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user >=20 =3D=3D=3D=3D=3D Rob Baccus Email: rb...@go... =09 _______________________________ Do you Yahoo!? Express yourself with Y! Messenger! Free. Download now.=20 http://messenger.yahoo.com ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=3D5047&alloc_id=3D10808&op=3Dclick _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |