使用HttpClient登陆web-login使用JerichoHTMLParser和htmlparser抓取html
来源:互联网 发布:linux查看jar包内文件 编辑:程序博客网 时间:2024/06/05 15:21
httpclient http://jakarta.apache.org/commons/httpclient/
Jericho HTML Parser http://jerichohtml.sourceforge.net/
htmlparser http://sourceforge.net/projects/htmlparser/
HttpClientLogin.java
package web;
import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import au.id.jericho.lib.html.FormField;
import au.id.jericho.lib.html.FormFields;
import au.id.jericho.lib.html.Source;
public class HttpClientLogin{
public static void main(String args[]) throws HttpException, IOException,
ParserException {
HttpClient client = new HttpClient();
client.getParams().setContentCharset("utf-8");
client.getHostConfiguration().setHost("127.0.0.1", 80, "http");
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod authget = new GetMethod("/admin/login.php");
client.executeMethod(authget);
authget.releaseConnection();
PostMethod authpost = new PostMethod("/admin/login.php");
NameValuePair action = new NameValuePair("action",
"http://127.0.0.1/admin/login.php");
NameValuePair method = new NameValuePair("method", "post");
NameValuePair userid = new NameValuePair("TextBox1", "kefu");
NameValuePair password = new NameValuePair("TextBox2", "kefu");
authpost.setRequestBody(new NameValuePair[] { method, action, userid,
password, });
client.executeMethod(authpost);
authpost.releaseConnection();
String anotherPage = "/admin/index.php";
GetMethod anotherPageGet = new GetMethod(anotherPage);
client.executeMethod(anotherPageGet);
Source source = new Source(anotherPageGet.getResponseBodyAsStream());
source.fullSequentialParse();
FormFields formFields = source.findFormFields();
String temp = "";
for (Iterator i = formFields.iterator(); i.hasNext();) {
FormField formField = (FormField) i.next();
if (formField.getName() != null
&& formField.getName().equals("temp")) {
temp = (String) formField.getFormControl().getAttributesMap()
.get("value");
}
}// 抓取 temp filed 当访问该page产生的临时值
NameValuePair temp_ = new NameValuePair("temp", temp);
PostMethod anotherPagePost = new PostMethod(anotherPage);// 提交
anotherPagePost.setRequestBody(new NameValuePair[] { temp_ });// 加入该查询条件
client.executeMethod(anotherPagePost);// 提交查询条件
String resultHtml = anotherPagePost.getResponseBodyAsString();
Parser parser = Parser.createParser(new String(resultHtml.getBytes(),
"8859_1"), "8859-1");
String filterStr = "table";
NodeFilter filter = new TagNameFilter(filterStr);
NodeList nodes = parser.extractAllNodesThatMatch(filter);// 抓取查询结果
Node node = nodes.elementAt(3);// 截取talbe
String result = new String(node.toHtml().getBytes("8859_1"));
}
}
- 使用HttpClient登陆web-login使用JerichoHTMLParser和htmlparser抓取html
- Httpclient和htmlparser使用
- 使用HttpClient登陆网站 抓取页面数据
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用HttpClient和HtmlParser实现网络爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- 自动化测试工具兼容性报告
- .Net动态加载程序集
- WinRunner介绍
- 用VisualC#.NET编写服务器日期控件
- MD5算法之C#程序 MD5算法描述
- 使用HttpClient登陆web-login使用JerichoHTMLParser和htmlparser抓取html
- 功能测试自动化的投入和产出
- XSD中内置的数据类型(总结)
- 对QTP中Check Point的较为深入理解
- 在ASP.Net中长内容自动分页的实现
- 企业级应用网页设计的几点体会
- 常用算法设计方法
- 用VisualC#中轻松浏览数据库记录
- Flash Remoting的核心技术:AMF