朋友需要所以做了个小工具,登陆搜外论坛然后再灌水区跟帖,登陆代码如下:
Connection conn = Jsoup
.connect("http://bbs.seowhy.com/member.php?mod=logging&action=login&loginsubmit=yes&inajax=1")
// 添加登陆表单参数 useername
.data("username", "zhanghao")
// 添加登陆表单参数password MD5加密串
.data("password", "MD5加密串")
// UserAgent 模拟
.userAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; MALC)")
// 设置编码
.postDataCharset("GBK")
// 忽略Response 类型
.ignoreContentType(true)
// 设置请求方式
.method(Method.POST)
// 设置超时等待
.timeout(100000);
Response response = conn.execute();
if (response.body().contains("succeedhandle_")) {
System.out.println("登陆成功");
} else if (response.body().contains("errorhandle_") || true) {
System.out.println("登陆失败");
System.out.println(response.body());
}
Map<String, String> cookies = response.cookies();
Set<String> ks = cookies.keySet();
for (Map.Entry<String, String> entry : cookies.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
需要build Jsoup
Jsoup 官网:http://jsoup.org/
最新版本 :1.8.3
官网jar包下载链接:http://jsoup.org/packages/jsoup-1.8.3.jar
官网源码下载链接:http://jsoup.org/packages/jsoup-1.8.3-sources.jar
官网javadoc下载链接:http://jsoup.org/packages/jsoup-1.8.3-javadoc.jar
官方在线API:http://jsoup.org/apidocs/
Selector API:http://jsoup.org/apidocs/org/jsoup/select/Selector.html