最近这个小私活有个地方比较变态,让我登陆一个系统自动下载一个excel备份和入库,尤其讨厌的是excel的是通过一大堆条件查询出来的,有些条件明面上还没有,需要自己去捉个提取,经过反复测试,终于能拿到符合条件的东西了,初步代码如下:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response = null;
HttpEntity entity = null;
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
HttpPost httpost = new HttpPost("http://....../cdc/login.do?formAction=index&moduleFlag=DI");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("username", "U25655556"));
nvps.add(new BasicNameValuePair("passwd", "ruanjian"));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
httpclient.execute(httpost);
httpost.abort();
} catch (IOException e) {
e.printStackTrace();
}
HttpPost excelExport = new HttpPost("http://....../cdc/report/reportExcel.do?formAction=listreport");
List<NameValuePair> promaters = new ArrayList<NameValuePair>();
// promaters.add(new BasicNameValuePair("ListZoneCode", "11010600"));
// promaters.add(new BasicNameValuePair("QueryZoneCode", "11010600"));
// promaters.add(new BasicNameValuePair("apanagecode", "11010600"));
// promaters.add(new BasicNameValuePair("rptorgcode", "11010600"));
promaters.add(new BasicNameValuePair("zoneselect", "apanagecode"));
promaters.add(new BasicNameValuePair("date_name_s", "intime"));
promaters.add(new BasicNameValuePair("filltime_start", "2010-05-31"));
promaters.add(new BasicNameValuePair("filltime_stop", "2010-05-31"));
// promaters.add(new BasicNameValuePair("disflag", "0"));
promaters.add(new BasicNameValuePair("audit_flag", "1"));
try {
excelExport.setEntity(new UrlEncodedFormEntity(promaters));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
// ResponseHandler<String> responseHandler = new BasicResponseHandler();
response = httpclient.execute(excelExport);
entity = response.getEntity();
} catch (IOException e) {
e.printStackTrace();
}
try {
// InputStream inputStream = entity.getContent();
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
// CSVReader reader = new CSVReader(inputStreamReader);
// List<String[]> list = reader.readAll();
// for (String[] strings : list) {
// for (String string : strings) {
// System.out.println(string);
// }
// }
FileOutputStream outputStream = new FileOutputStream("E:\\my.csv");
entity.writeTo(outputStream);
outputStream.close();
// inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
}
分享到:
相关推荐
HttpClient抓取网页Demo,HttpClient 的入门示例,配合blog文章的附件
Jsoup+httpclient模拟登陆和抓取页面.pdf
httpClient+jsoup抓取网页数据实例和jar包
Jsoup+httpclient 模拟登陆和抓取页面 package com.app.html; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader...
java httpclient 抓取 数据 和jar 包
HttpClient网页抓取工具包整合,
httpclient绕过验证码直接抓取,you know
使用HttpClient登录网易邮箱 博文链接:https://bps.iteye.com/blog/136231
httpclient远程网页抓取工具,可以继承到web项目工程中,很好哟,还等什么?
重新封装的HttpClient类 用于网页抓取的朋友们可以留着,还算比较完善!
NULL 博文链接:https://zhouxianglh.iteye.com/blog/832696
httpclient绕过登陆验证码直接抓取内部数据
利用httpClient+jsoup技术进行网页数据的获取,以网易贵金属为例~
httpClient 中文指导手册 教你如何用登录 如何抓取网页等
Java抓取https网页数据,解决peer not authenticated异常。导入eclipse就能运行,带有所用的jar包(commons-httpclient-3.1.jar,commons-logging.jar,httpclient-4.2.5.jar,httpcore-4.2.4.jar)
HttpClient get、post 请求,抓取网络数据,jar包以及源码
这是httpclient应用所有jar,用户抓取请求内容,本人平时用的就是这个,欢迎下载!
httpclient实现代理登录和信息抓取所需的jar包
一个通过httpclient抓取火车票信息的程序,需要修改下才能跑通,需要自己封装下httpclient,然后用get方式调用,还有fastJson,需要自己去解析下获得的数据,catchTrainInfo()是入口方法 import java.io....