使用<noscript> </noscript>在网站上发布表单

时间:2014-06-27 02:27:55

标签: android web

所以我正在开发一个Android应用程序,旨在登录网站并从返回的页面中抓取数据。但是,我无法使用Jsoup或Apache HttpClient等方法登录网站,因为这些方法会触发页面上的响应,提示我启用JavaScript以访问该页面。 HtmlUnit将是一个很好的解决方法,但是大量的JAR禁止我在Android应用程序上使用它。

我应该怎样做才能解决/解决这个问题?

这是我要登录的网站: https://grades.bsd405.org/Pinnacle/Gradebook/Logon.aspx

由于

编辑:这是jSoup的代码

try {
        Document doc = Jsoup.connect("https://grades.bsd405.org/Pinnacle/Gradebook/Logon.aspx")
                .data("ctl00$ContentPlaceHolder$Username", "myusername")
                .data("ctl00$ContentPlaceHolder$Password","mypassword")
                .data("ctl00$ContentPlaceHolder$LogonButton","Sign in").post();
        System.out.println(doc.text());
    } catch (IOException e) {
        e.printStackTrace();
    }

对于HtmlUnit

public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
      final WebClient webClient = new WebClient();
      webClient.getOptions().setUseInsecureSSL(true);
      webClient.getOptions().setThrowExceptionOnScriptError(false);
        final HtmlPage page1 = webClient.getPage("https://grades.bsd405.org/Pinnacle/Gradebook/InternetViewer/GradeSummary.aspx");

        final HtmlForm form = page1.getForms().get(0);

        final HtmlSubmitInput button = form.getInputByName("ctl00$ContentPlaceHolder$LogonButton");
        final HtmlTextInput textField = form.getInputByName("ctl00$ContentPlaceHolder$Username");
        final HtmlPasswordInput passField = form.getInputByName("ctl00$ContentPlaceHolder$Password");

        textField.setValueAttribute("myusername");
        passField.setValueAttribute("mypassword");

        final HtmlPage page2 = button.click();
        displayGrades(page2);

        webClient.closeAllWindows();
}

private static void displayGrades(HtmlPage page) {
    System.out.println(page.asXml());

    HtmlDivision div = (HtmlDivision) page.getHtmlElementById("Content");
    final HtmlTable table = (HtmlTable) div.getByXPath("//table[@class='reportTable']").get(0);
    try{
        System.out.println(table.asText());
    }catch (NullPointerException e){
        e.printStackTrace();
    }
}

0 个答案:

没有答案