This Question is Possibly Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
1 Replies Last post: Aug 26, 2008 11:41 AM by Vladimir Ikryanov  
hegh   7 posts since
Aug 15, 2008
Currently Being Moderated

Aug 15, 2008 8:13 PM

How to get the navigated page's content?

 

In my example, the page a.html will navigate to a new page(http://www.google.com/) automatically in 2 seconds.

 

 

At first, I load page a.html in to a WebBrowser instance:browser, but then I can't use  browser.getContent() to get the content of google's index page?

 

 

How to solve it? Thanks a lot!

 

The code is available:

 

Attachments:
Vladimir Ikryanov TeamDev Ltd. 402 posts since
Apr 24, 2006
Currently Being Moderated
1. Aug 26, 2008 11:41 AM in response to: hegh
Re: How to get the navigated page's content?

Hello,

 

To solve this issue you need to catch the moment when page redirects to a Google page. The following solution shows how you can do this:

 


        WebBrowser browser = new HeadlessBrowser();
        browser.navigate("file://" + "F:/a.html");
        browser.waitReady();
        browser.addNavigationListener(new NavigationEventAdapter()
        {
            public void entireDocumentCompleted(WebBrowser webBrowser, String url)
            {
                String content = webBrowser.getContent();
                System.out.println(content);
            }
        });

Regards,

Vladimir Ikryanov

More Like This

  • Retrieving data ...