Created
October 19, 2016 03:25
-
-
Save fanqi/98458c275dc33e8eb4f79e847d3cef27 to your computer and use it in GitHub Desktop.
Jsoup模拟表单登录的例子
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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