2013-02-19 50 views
0

我需要下載一個特定的Facebook頁面的源代碼。 所以我想我會登錄到Facebook,然後下載源代碼。 但是關於我的信息記錄在被簡單地丟失,當我嘗試下載源代碼ROM看來我還是登出我的應用程序的另一個網址。下載Facebook頁面源代碼

因此,這裏是我的代碼:

public class App 
{ 
    public static void main(String[] args) throws IOException 
    { 
     System.out.println("Hello World!"); 

     final WebClient webClient = new WebClient(); 
     final HtmlPage page1 = webClient.getPage("http://www.facebook.com"); 
     final HtmlForm form = (HtmlForm) page1.getElementById("login_form"); 

     final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0); 
     final HtmlTextInput textField = form.getInputByName("email"); 
     textField.setValueAttribute("email"); 
     final HtmlPasswordInput textField2 = form.getInputByName("pass"); 
     textField2.setValueAttribute("password"); 
     final HtmlPage page2 = button.click(); 


     HtmlPage weread = webClient.getPage("http://apps.facebook.com/ireadit/?fb_source=bookmark_apps&ref=bookmarks&count=0&fb_bmpos=2_0"); 

        System.out.println(weread.asXml()); 



    } 

我希望你明白我的idea..any建議,該怎麼辦呢?

回答

0

看來你正在使用HtmlUnit,你沒有在你的問題中指定。

認證工作與餅乾。您尚未將其納入您的代碼。當您第一次登錄時,服務器會向您發送Cookie,您需要捕獲並重新發送後續請求。我不是很熟悉的HtmlUnit,但它看起來像它,你可以用它來獲得餅乾這樣那麼CookieManager類:

webClient.getCookieManager().getCookies(); 

您可能也想看看this question