2013-02-19 49 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