How can I parse dynamic content from a web page?

前端 未结 1 580
难免孤独
难免孤独 2021-01-18 19:15

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-generate

相关标签:
1条回答
  • 2021-01-18 19:39

    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!

    0 讨论(0)
提交回复
热议问题