从网站中把数据都读到一个文本文件中。
来源:互联网 发布:西安爱知中学在哪里 编辑:程序博客网 时间:2024/05/14 01:30
public class AnderuiDataAnalyser {
private static HttpService client = HttpService.getInstance();
private static ObjectMapper mapper = new ObjectMapper();
public static void main(String[] args) throws Exception {
execute();
}
public static void execute() throws Exception {
HttpGet get = new HttpGet("http://115.28.238.28:8080/SSHTEST/");
CloseableHttpResponse response = client.execute(get);
response.close();
HttpPost post = new HttpPost("http://115.28.238.28:8080/SSHTEST/user_verifyUserInfo");
List<NameValuePair> nvpList = new ArrayList<>();
nvpList.add(new BasicNameValuePair("username", "111"));
nvpList.add(new BasicNameValuePair("password", "123"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvpList, "UTF-8");
post.setEntity(entity);
response = client.execute(post);
response.close();
String template = "http://115.28.238.28:8080/SSHTEST/customManager/whole_data_list?_dc=1452576686815&page=%d&start=%d&limit=1000";
FileWriter writer = new FileWriter("d:/carresult.txt", true);
for(int i = 1; i <= 270; i++) {
String url = String.format(template, i, (i - 1) * 1000);
HttpGet getData = new HttpGet(url);
response = client.execute(getData);
String resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
response.close();
Map<String, Object> valueMap = mapper.readValue(resultString, Map.class);
List<Map<String, Object>> carList = (List<Map<String, Object>>) valueMap.get("data");
for(Map<String, Object> carMap : carList) {
String licenPlate = (String) carMap.get("licenPlate");
if( licenPlate == null )
continue;
String frameNum = (String) carMap.get("frameNum");
if( frameNum == null )
continue;
String engineNum = (String) carMap.get("engineNum");
if( engineNum == null )
continue;
String labelType = (String) carMap.get("labelType");
if( labelType == null )
continue;
String customName = (String) carMap.get("customName");
if( customName == null )
continue;
String conPhone = (String) carMap.get("conPhone");
if( conPhone == null )
continue;
String ensExpDate = (String) carMap.get("ensExpDate");
if( ensExpDate == null )
continue;
writer.write(carMap.get("licenPlate").toString() + "," + carMap.get("frameNum").toString() + "," + carMap.get("engineNum").toString() + "," + carMap.get("labelType").toString() + "," + carMap.get("customName").toString() + "," + carMap.get("conPhone").toString() + "," + carMap.get("ensExpDate").toString() + "\r\n");
}
writer.flush();
}
writer.close();
}
}
private static HttpService client = HttpService.getInstance();
private static ObjectMapper mapper = new ObjectMapper();
public static void main(String[] args) throws Exception {
execute();
}
public static void execute() throws Exception {
HttpGet get = new HttpGet("http://115.28.238.28:8080/SSHTEST/");
CloseableHttpResponse response = client.execute(get);
response.close();
HttpPost post = new HttpPost("http://115.28.238.28:8080/SSHTEST/user_verifyUserInfo");
List<NameValuePair> nvpList = new ArrayList<>();
nvpList.add(new BasicNameValuePair("username", "111"));
nvpList.add(new BasicNameValuePair("password", "123"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvpList, "UTF-8");
post.setEntity(entity);
response = client.execute(post);
response.close();
String template = "http://115.28.238.28:8080/SSHTEST/customManager/whole_data_list?_dc=1452576686815&page=%d&start=%d&limit=1000";
FileWriter writer = new FileWriter("d:/carresult.txt", true);
for(int i = 1; i <= 270; i++) {
String url = String.format(template, i, (i - 1) * 1000);
HttpGet getData = new HttpGet(url);
response = client.execute(getData);
String resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
response.close();
Map<String, Object> valueMap = mapper.readValue(resultString, Map.class);
List<Map<String, Object>> carList = (List<Map<String, Object>>) valueMap.get("data");
for(Map<String, Object> carMap : carList) {
String licenPlate = (String) carMap.get("licenPlate");
if( licenPlate == null )
continue;
String frameNum = (String) carMap.get("frameNum");
if( frameNum == null )
continue;
String engineNum = (String) carMap.get("engineNum");
if( engineNum == null )
continue;
String labelType = (String) carMap.get("labelType");
if( labelType == null )
continue;
String customName = (String) carMap.get("customName");
if( customName == null )
continue;
String conPhone = (String) carMap.get("conPhone");
if( conPhone == null )
continue;
String ensExpDate = (String) carMap.get("ensExpDate");
if( ensExpDate == null )
continue;
writer.write(carMap.get("licenPlate").toString() + "," + carMap.get("frameNum").toString() + "," + carMap.get("engineNum").toString() + "," + carMap.get("labelType").toString() + "," + carMap.get("customName").toString() + "," + carMap.get("conPhone").toString() + "," + carMap.get("ensExpDate").toString() + "\r\n");
}
writer.flush();
}
writer.close();
}
}
1 0
- 从网站中把数据都读到一个文本文件中。
- 能否从一个没有读到数据SqlDataReader中创建DataTable
- 把数据库中的数据读到EXCEL中
- 从文本文件中读取数据
- 从文本文件中读取数据
- 把整个文本文件内容读到一个string里
- informix 把数据从一个表倒到另外一个表中
- C++从文本文件中读一行数据
- 从文本文件中读取数据画图
- 从Oracle中导出数据到文本文件
- 43节从文本文件中读入数据!
- python 从文本文件中解析数据
- 从一个文本文件中读取数据显示在网格控件mshflexgrid中
- java中关于判断文本文件读到文件尾
- 从一个数据库中调取数据,把数据存入里一个数据库中。
- 将一个ANSI编码格式纯文本文件以UTF-8的形式读到另一个文件中去
- //将一个ANSI编码格式纯文本文件以UTF-8的形式读到另一个文件中去
- 怎么把多个表的数据读到一个DATAGRID里面?
- JAVA实现把指定文件夹下的所有文件压缩成zip包
- ios开发小技巧
- SPRING-SECURITY安全Web框架配置
- 欢迎使用CSDN-markdown编辑器
- myeclipse2015 git 操作
- 从网站中把数据都读到一个文本文件中。
- Android实现类似QQ的滑动删除效果
- 重回以前公司
- oracle的MAX_DUMP_FILE_SIZE参数和ora-02065
- 判断字符串是否全部是数字
- java web 项目中 简单定时器实现 Timer
- UIColor 类扩展支持十六进制
- (Mac)Rails项目使用七牛上传及下载文件
- 如何蹭网