无法使用jsoup登录到aspx页面

时间:2018-06-11 08:44:13

标签: asp.net web-scraping jsoup screen-scraping

每次我尝试登录时,都会返回相同的登录页面,如果我在连接的任何地方出错,请指导我。

注意:我的登录按钮是输入类型图像,它没有值属性

    String userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
    String username = "username";  
     String password = "password"; 
     String url = "https://www.ipointweb.net/Secure/Login.aspx";
     Connection.Response loginForm = Jsoup.connect(url).timeout(0)
            .method(Connection.Method.GET)
            .execute();
     Document loginPage = loginForm.parse();
     Document doc=null;
    Connection.Response mainPage = Jsoup.connect(url).timeout(0)

              .data("ctl00$ContentPlaceHolder1$Login$UserName",username)
             .data("ctl00$ContentPlaceHolder1$Login$Password",password)
             .data("ctl00$ContentPlaceHolder1$Login$LoginButton", "")
             .data("ctl00_RadStyleSheetManager1_TSSM",loginPage.getElementById("ctl00_RadStyleSheetManager1_TSSM").val())
             .data("__EVENTTARGET", "")
             .data("__EVENTARGUMENT","")
              .data("__VIEWSTATE", loginPage.getElementById("__VIEWSTATE").val())
              .data("__VIEWSTATEGENERATOR", loginPage.getElementById("__VIEWSTATEGENERATOR").val())
              .data("__EVENTVALIDATION", loginPage.getElementById("__EVENTVALIDATION").val())
             .userAgent(userAgent)
             .followRedirects(true)
             .cookies(loginForm.cookies())
             .method(Connection.Method.POST)
             .execute();
        System.out.println(mainPage.parse().text());
    Map<String, String> cookies = mainPage.cookies();

    Document evaluationPage = Jsoup.connect("https://www.ipointweb.net/secure/authorised/secAgency/Home.aspx").timeout(0)
            .cookies(cookies).execute().parse();

 System.out.println(evaluationPage.text());

0 个答案:

没有答案