Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse dynamic content from a web page?

I try to get a proxy list from this url:

Free proxy list

This would be cool, but port number is dynamic JavaScript content. How can I get JavaScript-generated content from this page? I have jsoup and djNativeSwing but I want do this in background thread.

JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://spys.ru/en/free-proxy-list/");
System.out.println(webBrowser.getHTMLContent());

this code returns a Null result. Help please.

like image 769
Trump Avatar asked Nov 03 '22 17:11

Trump


1 Answers

The webbrowser hasn't finnished loading when you call the getHtmlContent() method. Use something like this instead:

JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://spys.ru/en/free-proxy-list/");
webBrowser.addWebBrowserListener(new WebBrowserListener(){
   public void loadingProgressChanged(WebBrowserEvent e){
       if(e.getWebBrowser().getLoadingProgress()==100)
            System.out.println(webBrowser.getHTMLContent());
   }
}
/* Note: I wrote this in the comment field without any testing,
   you probably have to make the webBrowser final. */

JavaDocs is your friend!

like image 121
Henrik Karlsson Avatar answered Nov 08 '22 05:11

Henrik Karlsson