簡體   English   中英

如何使用Java中的htmlunit登錄到Twitter?

[英]How to login to Twitter using htmlunit in Java?

我正在嘗試使用Java的htmlunit軟件包登錄Twitter。 但是我得到了錯誤:com.gargoylesoftware.htmlunit.html.HtmlPasswordInput無法轉換為com.gargoylesoftware.htmlunit.html.HtmlTextInput

    WebClient webClient = new WebClient(BrowserVersion.CHROME);
    HtmlPage page = webClient.getPage("https://www.twitter.com/");
    HtmlForm form = page.getForms().get(1);
    form.reset();
    HtmlTextInput username = form.getInputByName("session[password]");

    username.setText("xxxxxxx");

    HtmlPasswordInput password = form.getInputByName("session[password]");

    password.setText("xxxxxxx");

    HtmlInput button = form.getInputByValue("Log in");
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    HtmlPage p = button.click();

您代碼中的以下行會導致問題

HtmlTextInput username = form.getInputByName("session[password]");

它應該是

HtmlTextInput username = form.getInputByName("session[username_or_email]");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM