Skip to content

Instantly share code, notes, and snippets.

@fanqi
Created October 19, 2016 03:25
Show Gist options
  • Save fanqi/98458c275dc33e8eb4f79e847d3cef27 to your computer and use it in GitHub Desktop.
Save fanqi/98458c275dc33e8eb4f79e847d3cef27 to your computer and use it in GitHub Desktop.
Jsoup模拟表单登录的例子
package xyz.fanqi.jsoup;
import org.jsoup.Connection;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class JsoupLoginTest {
public static void main(String[] args) throws Exception {
Response response = Jsoup.connect("loginFormActionURL")
.data("userName", "userName")
.data("password", "password")
.method(Connection.Method.POST)
.execute();
Document doc = Jsoup.connect("pageURL")
.cookies(response.cookies())
.ignoreContentType(true)
.get();
System.out.println(doc.text());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment