我設法從另一個線程來源代碼,但我似乎無法讓它工作,有很多紅線!我需要更改什麼才能使其適用於需要登錄的我的網頁?如何讓這個自動化的java登錄使用JSoup工作?
Connection.Response loginForm = Jsoup.connect("https://login.to/")
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.method(Connection.Method.GET)
.execute();
Connection.Response loginFormFilled = Jsoup.connect("https://login.to/")
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.followRedirects(true)
.referrer("https://login.to/")
.data("LOGON", "user")//check the form to find field name for user name
.data("PASSWORDS", "pass")//check the form to find field name for user password
.cookies(loginForm.cookies())
.method(Connection.Method.POST)
.execute();
int statusCode = loginFormFilled.statusCode();
Map<String, String> cookies = loginFormFilled.cookies();
編輯:NEW CODE
try{
Connection.Response loginForm = Jsoup.connect("https://www.studentinvestor.org/secure/login.php")
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.method(Connection.Method.GET)
.execute();
Connection.Response loginFormFilled = Jsoup.connect("https://www.studentinvestor.org/secure/login.php")
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.followRedirects(true)
.referrer("https://login.to/")
.data("team-name", "stockblockers 99")//check the form to find field name for user name
.data("team-password", "monkey1")//check the form to find field name for user password
.cookies(loginForm.cookies())
.method(Connection.Method.POST)
.execute();
int statusCode = loginFormFilled.statusCode();
Map<String, String> cookies = loginFormFilled.cookies();
System.out.println(statusCode);
}catch(Exception e){
e.printStackTrace();}
}
}
編輯2:餅乾不工作! 所以我有一個自動化的java登錄。一旦程序執行該方法,並返回200狀態碼以顯示它成功,這意味着我已登錄(對吧?)。但是,當程序嘗試下載網頁的HTML並將其輸出到屏幕上時,輸出的HTML是登錄屏幕,而不是登錄後的網頁的HTML。
我猜這已經是與餅乾,因爲有在「曲奇」黃線下方
Map<String, String> cookies = loginFormFilled.cookies();
「連接」「loginForm」,「loginFormFilled」和「映射」下的紅線 – user296950 2014-11-02 14:52:47
不要向同一帖子添加不同的問題。創建一個新的職位,包括所有相關的代碼和任何產生的錯誤 – Reimeus 2014-11-02 15:46:47
在計算器上的90分鐘規則阻止我 – user296950 2014-11-02 15:57:41