java、HttpClient,post请求、get请求,抓取网络数据

源码jar包下载地址:

https://download.csdn.net/download/xubenxismile/11141011

package com.dw;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.classloader.IoUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

import com.dareway.apps.process.component.material.MaterialNames;
import com.dareway.framework.common.GlobalNames;
import com.dareway.framework.exception.AppException;
import com.dareway.framework.mail.MailInfo;
import com.dareway.framework.mail.MailUtil;
import com.dareway.framework.plugin.FormalRunDB;
import com.dareway.framework.util.DataObject;
import com.dareway.framework.util.DataStore;
import com.dareway.framework.util.SecUtil;
import com.dareway.framework.util.Sql;
import com.dareway.framework.util.database.Transaction;
import com.dareway.framework.util.database.TransactionManager;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
 * 数据抽取测试类
 * 
 * @author xbx
 *
 */
public class Main_xbx {
	private static HttpContext localContext = new BasicHttpContext();

	public static void main(String[] args) throws Exception {

		doPost();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(Long.valueOf("1267545600000"));
        Date date = new Date(lt);
        String res = simpleDateFormat.format(date);
//    	  DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+08:00");  //yyyy-MM-dd'T'HH:mm:ss.SSSZ;yyyy-MM-dd'T'HH:mm:ss.SSSXXX
//		  Date date = df.parse("2010-03-03T00:00:00+08:00");
//		  System.out.println(date);
//    	  System.out.println(1);
//    	  //Wed Mar 03 00:00:00 CST 2010
//        //getData();
		// sendMail();
		// sendMail2();
	}

	/**
	 * httpGet
	 * 
	 * @description
	 * @author 徐本锡
	 * @date 2019年4月16日
	 * @version V1.0
	 */
	public static void getData() throws AppException {
		HttpResponse httpResponse = null;
		HttpClient httpClient = new DefaultHttpClient();
		HttpGet get = new HttpGet(
				"http://openapi.tdata.cn/api/search?keyword=小米科技有限责任公司&province=BJ&pageSize=20&pageIndex=1&dtype=json&apikey=am5neGI6am5neGI=");
		try {
			httpResponse = httpClient.execute(get, localContext);
			HttpEntity httpEntity = httpResponse.getEntity();
			String httpResult = EntityUtils.toString(httpEntity);
			// DataObject vdo = DataObject.parseJSON(httpResult);
			JSONArray jsStr = JSONArray.fromObject(httpResult);
			System.out.println(httpResult);
			// "{"status":"200","message":"查询成功","paging":{"totalRecords":"4","pageIndex":"1","pageSize":"20"},"result":[{"keyNo":"9cce0780ab7644008b73bc2120479d31","companyName":"小米科技有限责任公司","operName":"雷军","startDate":"2010-03-03T00:00:00","status":"开业","regNo":"91110108551385082Q","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"7d2c3bc3681d467d78ebdbd988ee3e5b","companyName":"北京小米熊教育科技有限责任公司","operName":"周晓敏","startDate":"2009-02-13T00:00:00","status":"开业","regNo":"110108011627892","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"ee92647afee609db9b431e4234557374","companyName":"北京创派力量科技有限公司","operName":"丁鹏飞","startDate":"2013-05-24T00:00:00","status":"开业","regNo":"911101080696123204","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"add69f81b86b006897fa3d6d90e97fed","companyName":"英鹏互娱科技(北京)有限公司","operName":"林军","startDate":"2013-11-05T00:00:00","status":"注销","regNo":"91110108082888022Q","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"}]}"
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// 发邮件
	static void sendMail() throws AppException {
		DataObject result = new DataObject();
		System.out.println("开始发邮件");

		// 发送邮箱设置
		String EmailSmtp = "smtp.163.com";// 邮箱协议
		String EmailUser = "dyetdz";// 用户名
		String EmailPassword = "dareway2019";// 密码 aaa123 授权码 dareway2019
		String EmailFrom = "[email protected]";// 邮箱地址

		// 接受设置
		String mailTitle = "测试javamail";// 邮件标题
		String autoMsg = "测试内容物";// 邮件内容
		String email = "[email protected]";// 接收邮箱

		try {

			String[] toMail = { email };
			MailInfo mailinfo = new MailInfo();
			mailinfo.setSmtp(EmailSmtp);
			mailinfo.setSmtpUser(EmailUser);
			mailinfo.setSmtpPassword(EmailPassword);
			mailinfo.setFrom(EmailFrom);
			mailinfo.setSubject(mailTitle);// 设置邮件主题
			mailinfo.setContent(autoMsg);// 设置邮件内容
			mailinfo.setTo(toMail);// 设置收件人
			// 要用公共邮箱给上面那些人发邮件,这个是公共邮箱的密码
			new MailUtil(mailinfo).send();
			result.put("result", true);
			System.out.println("完成发邮件");
		} catch (Exception e) {
			System.out.println("发送邮件失败!异常信息:" + e.getMessage());
		}
	}

	static void sendMail2() throws AppException {

		String host = "smtp.163.com";
		String user = "dyetdz";
		String pwd = "dareway2019";
		String from = "[email protected]";
		String to = "[email protected]";

		String subject = "javaMail方法测试";

		Properties props = new Properties();

		// 设置发送邮件的邮件服务器的属性(这里使用网易的smtp服务器)
		props.put("mail.smtp.host", host);
		// 需要经过授权,也就是有户名和密码的校验,这样才能通过验证(一定要有这一条)
		props.put("mail.smtp.auth", "true");

		// 用刚刚设置好的props对象构建一个session
		Session session = Session.getDefaultInstance(props);

		// 有了这句便可以在发送邮件的过程中在console处显示过程信息,供调试使
		// 用(你可以在控制台(console)上看到发送邮件的过程)
		session.setDebug(true);

		// 用session为参数定义消息对象
		MimeMessage message = new MimeMessage(session);
		try {
			// 加载发件人地址
			message.setFrom(new InternetAddress(from));
			// 加载收件人地址
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
			// 加载标题
			message.setSubject(subject);

			// 向multipart对象中添加邮件的各个部分内容,包括文本内容和附件
			Multipart multipart = new MimeMultipart();

			// 设置邮件的文本内容
			BodyPart contentPart = new MimeBodyPart();
			contentPart.setText("邮件的具体内容在此");
			multipart.addBodyPart(contentPart);
			// 添加附件
//			BodyPart messageBodyPart = new MimeBodyPart();
//			DataSource source = new FileDataSource(affix);
			// 添加附件的内容
//			messageBodyPart.setDataHandler(new DataHandler(source));
			// 添加附件的标题
			// 这里很重要,通过下面的Base64编码的转换可以保证你的中文附件标题名在发送时不会变成乱码
//			sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
//			messageBodyPart.setFileName("=?GBK?B?" + enc.encode(affixName.getBytes()) + "?=");
//			multipart.addBodyPart(messageBodyPart);

			// 将multipart对象放到message中
			message.setContent(multipart);
			// 保存邮件
			message.saveChanges();
			// 发送邮件
			Transport transport = session.getTransport("smtp");
			// 连接服务器的邮箱
			transport.connect(host, user, pwd);
			// 把邮件发送出去
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

/*	*//**
	 * 信息化项目数据抽取
	 * @description 
	 * @author 徐本锡
	 * @date 2019年4月16日
	 * @version V1.0
	 *//*
	public static void getData() throws AppException {
		HttpResponse httpResponse = null;
		HttpClient httpClient = new DefaultHttpClient();
		HttpGet get = new HttpGet(
				"http://openapi.tdata.cn/api/search?keyword=小米科技有限责任公司&province=BJ&pageSize=20&pageIndex=1&dtype=json&apikey=am5neGI6am5neGI=");
		try {
			httpResponse = httpClient.execute(get, localContext);
			HttpEntity httpEntity = httpResponse.getEntity();
			String httpResult = EntityUtils.toString(httpEntity);
			// DataObject vdo = DataObject.parseJSON(httpResult);
			JSONArray jsStr = JSONArray.fromObject(httpResult);
			System.out.println(httpResult);
			// "{"status":"200","message":"查询成功","paging":{"totalRecords":"4","pageIndex":"1","pageSize":"20"},"result":[{"keyNo":"9cce0780ab7644008b73bc2120479d31","companyName":"小米科技有限责任公司","operName":"雷军","startDate":"2010-03-03T00:00:00","status":"开业","regNo":"91110108551385082Q","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"7d2c3bc3681d467d78ebdbd988ee3e5b","companyName":"北京小米熊教育科技有限责任公司","operName":"周晓敏","startDate":"2009-02-13T00:00:00","status":"开业","regNo":"110108011627892","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"ee92647afee609db9b431e4234557374","companyName":"北京创派力量科技有限公司","operName":"丁鹏飞","startDate":"2013-05-24T00:00:00","status":"开业","regNo":"911101080696123204","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"},{"keyNo":"add69f81b86b006897fa3d6d90e97fed","companyName":"英鹏互娱科技(北京)有限公司","operName":"林军","startDate":"2013-11-05T00:00:00","status":"注销","regNo":"91110108082888022Q","logoUrl":"http://openapi.tdata.cn/logo/img/default.png"}]}"
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	*/

	/**
	 * 发送 POST 请求(HTTP),参数为 Key-Value 形式
	 *
	 * @param apiUrl API接口URL
	 * @param params 参数map
	 * @return
	 */
	public static String doPost() {
/*
		PoolingHttpClientConnectionManager connMgr;
		RequestConfig requestConfig;
		int MAX_TIMEOUT = 7000;
		
		// 设置连接池
        connMgr = new PoolingHttpClientConnectionManager();
 
        // 设置连接池大小
        connMgr.setMaxTotal(100);
        connMgr.setDefaultMaxPerRoute(connMgr.getMaxTotal());
 
        RequestConfig.Builder configBuilder = RequestConfig.custom();
 
        // 设置连接超时
        configBuilder.setConnectTimeout(MAX_TIMEOUT);
 
        // 设置读取超时
        configBuilder.setSocketTimeout(MAX_TIMEOUT);
 
        // 设置从连接池获取连接实例的超时
        configBuilder.setConnectionRequestTimeout(MAX_TIMEOUT);
 
        // 在提交请求之前 测试连接是否可用
        connMgr.setValidateAfterInactivity(5000);
        // configBuilder.setStaleConnectionCheckEnabled(true);
 
        requestConfig = configBuilder.build();
		*/

/*		http://221.214.94.36:81/sxk/main
			
			123456*/
		String url = "http://221.214.94.36:81/sxk/mng/project/change/info/query";
		Map params=new HashMap();
		params.put("Accept", "application/json, text/javascript, */*; q=0.01");
		params.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		params.put("X-Requested-With", "XMLHttpRequest");
		params.put("Referer", "http://221.214.94.36:81/sxk/mng/project/change/info/index?v=1555459803922");
		params.put("Accept-Language", "zh-CN");
		params.put("Accept-Encoding", "gzip, deflate");
		params.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)");
		params.put("Host", "221.214.94.36:81");
		params.put("Content-Length", "65");
		params.put("DNT", "1");
		params.put("Connection", "Keep-Alive");
		params.put("Cache-Control", "no-cache");
		//params.put("Cookie", "td_cookie=18446744069731352277; JSESSIONID=2BA9A59C8E68D0633EC3678BDFFAC749; webfinal.session.errorCount=0; webfinal.session.id=51f435c7-5f0c-4e6c-a883-e2e0d9f43c2b");
	//	params.put("", "");
		params.put("_search", "false");
		params.put("nd", "1555402726472");
		params.put("rows", "300");
		params.put("page", "1");
		params.put("sidx", "CODE");
		params.put("sord", "desc");
		
		HttpResponse response = null;
		HttpClient httpClient = new DefaultHttpClient();
		String httpStr = null;
		HttpPost httpPost = new HttpPost(url);

		BasicCookieStore cookieStore = new BasicCookieStore();
        BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "58DEDE9E70972800E2DA909F3445661E");
        cookie.setVersion(0);
        cookie.setDomain("221.214.94.36");
        cookie.setPath("/sxk/mng/project/change/info/query");
        
        cookieStore.addCookie(cookie);
        //带有cookie的httpclient
        httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
        
       // httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();

        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000).setConnectionRequestTimeout(15000).build();
        
		try {
			httpPost.setConfig(requestConfig);
			List pairList = new ArrayList<>(params.size());
			for (Map.Entry entry : params.entrySet()) {
				NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
				pairList.add(pair);
			}
/*			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000)
					.setRedirectsEnabled(false) // 不自动重定向
					.build();
			httpPost.setConfig(requestConfig);
			httpPost.setHeader("Cookies","JSESSIONID=50889DEB8FDB5D48A82EBE6BB3CDE308;webfinal.session.errorCount=0;webfinal.session.id=fa82a6a5-8d8c-40c4-92ac-cb09df5350f9");
			*/
			httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
			
			response = httpClient.execute(httpPost);
			System.out.println(response.toString());
			HttpEntity entity = response.getEntity();
			

			int code = response.getStatusLine().getStatusCode();
			
			//重定向
			if(code==302){
/*				//释放
				httpPost.abort();
				httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.MICROSECONDS);
				
				HttpGet locationUrl = new HttpGet(response.getLastHeader("location").getValue());
				response = httpClient.execute(locationUrl);
				System.out.println(response.toString());
				entity = response.getEntity();*/
				System.out.println("302");
			}
			httpStr = EntityUtils.toString(entity, "UTF-8");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (response != null) {
				try {
					EntityUtils.consume(response.getEntity());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		System.out.println(httpStr);
		return httpStr;
	}
	
}
package com.dw;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.dom4j.DocumentException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.dareway.framework.common.GlobalNames;
import com.dareway.framework.exception.AppException;
import com.dareway.framework.plugin.FormalRunDB;
import com.dareway.framework.util.DataObject;
import com.dareway.framework.util.DataStore;
import com.dareway.framework.util.DateUtil;
import com.dareway.framework.util.Sql;
import com.dareway.framework.util.database.Transaction;
import com.dareway.framework.util.database.TransactionManager;

/**
 * 投资项目信息抽取
 * 
 * @author xbx
 *
 */
public class Main_TZXMXX_xbx {
	private static HttpContext localContext = new BasicHttpContext();
	private static StringBuffer sqlBF = new StringBuffer();
	private static int index = 0;
	private static Sql sql = new Sql();

	public static void main(String[] args) throws Exception {
		 
		//getXmList();
		//doGet_jbys();
		//getXmSqclList();
		doGet_fdyj();
	}

	/**
	 * httpGet抽取基本要素
	 * 
	 * @description
	 * @author 徐本锡
	 * @date 2019年4月16日
	 * @version V1.0
	 * @throws DocumentException 
	 */
	public static void doGet_fdyj() throws AppException {
		HttpResponse httpResponse = null;
		@SuppressWarnings("resource")
		HttpClient httpClient = new DefaultHttpClient();


		GlobalNames.CONFIGINWAR = "true";
		FormalRunDB.setFormalRunDB(false);//正式库
//		DebugModeConfig.setDebugMode(false);//非debug模式
		Transaction tr = TransactionManager.getTransaction();
		tr.begin();
		
		//删除版本号不同的材料
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" delete from ga0001.tzxmsxqd_fdyj a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd x where a.id=x.id and a.code=x.code and a.version=x.version) ");
		sql .setSql(sqlBF.toString());
		sql.executeUpdate();
		
		//查询需要爬取的项目
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" select a.id, a.type, a.org_name, a.inner_code, a.name, a.code, a.version ");
		sqlBF.append("   from ga0001.tzxmsxqd a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd_fdyj x where a.id=x.id and a.version=x.version and a.code=x.code)  ");
		sql .setSql(sqlBF.toString());
		DataStore vdsSXQD = sql.executeQuery();
		tr.commitWithoutStart();
		
		//循环请求数据
		int i=0;
		String id="", type="", org_name="", code="", version="", name="", inner_code="";
		String url = "";
		for(DataObject obj : vdsSXQD) {
			id = obj.getString("id", "");
			type = obj.getString("type", "");
			org_name = obj.getString("org_name", "");
			inner_code = obj.getString("inner_code", "");
			code = obj.getString("code", "");
			version = obj.getString("version", "");
			name = obj.getString("name", "");
			System.out.println("正在处理第"+ String.valueOf(++i) +"条事项:"+name);
			url = "http://221.214.94.36:81/sxk/main/power/tab/basiclaw/"+code+"/"+version+"?itemType="+type+"&v=1555587689300";
			HttpGet get = new HttpGet(url);
			
			GlobalNames.CONFIGINWAR = "true";
			FormalRunDB.setFormalRunDB(false);//正式库
//			DebugModeConfig.setDebugMode(false);//非debug模式
			tr = TransactionManager.getTransaction();
			tr.begin();
			
			try {
				httpResponse = httpClient.execute(get, localContext);
				HttpEntity httpEntity = httpResponse.getEntity();
				String httpResult = EntityUtils.toString(httpEntity);
				Document document = Jsoup.parse(httpResult);
				Elements elementsFDYJList = document.getElementsByAttributeValue("id","charge_fg");
				
				sqlBF.setLength(0);
				sqlBF.append(" INSERT INTO ga0001.tzxmsxqd_fdyj( ");
				sqlBF.append("             id, fgxh, type, org_name, inner_code, name, cqsj, code, version, ");
				sqlBF.append("             fdyj) ");
				sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ");
				sqlBF.append("             ?) ");
				sql .setSql(sqlBF.toString());
				int fgxh=0;
				if(elementsFDYJList.size()==0) {
					System.out.println("无");
					continue;
				}
				for (Element element : elementsFDYJList) {
//					Elements elementsKEY = element.getElementsByClass("item-left");
//					Elements elementsVALUE = element.getElementsByClass("item-right");
					String value = element.text().trim();
					index = 0;
					sql.setString(++index, id);
					sql.setString(++index, String.valueOf(++fgxh));
					sql.setString(++index, type);
					sql.setString(++index, org_name);
					sql.setString(++index, inner_code);
					sql.setString(++index, name);
					sql.setDateTime(++index, DateUtil.getDBTime());
					sql.setString(++index, code);
					sql.setString(++index, version);
					sql.setString(++index, value);
					sql.addBatch();
				}
				sql.executeBatch();
				tr.commitWithoutStart();
			} catch (IOException e) {
				tr.rollback();
				e.printStackTrace();
			}
		}
		
	}
	
	/**
	 * 抽取标准文书
	 * @description 
	 * @author 徐本锡
	 * @date 2019年4月18日
	 * @version V1.0
	 * @throws AppException 
	 */
	public static String getXmBzwsList() throws AppException {
		/*		
		http://221.214.94.36:81/sxk/main
		
		123456
		*/

		GlobalNames.CONFIGINWAR = "true";
		FormalRunDB.setFormalRunDB(false);//正式库
//		DebugModeConfig.setDebugMode(false);//非debug模式
		Transaction tr = TransactionManager.getTransaction();
		tr.begin();
		
		//删除版本号不同的材料
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" delete from ga0001.tzxmsxqd_bzws a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd x where a.id=x.id and a.item_code=x.code and a.item_version=x.version) ");
		sql .setSql(sqlBF.toString());
		sql.executeUpdate();
		
		//查询需要爬取的项目
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" select a.id, a.type, a.org_name, a.inner_code, a.name, a.code item_code, a.version item_version ");
		sqlBF.append("   from ga0001.tzxmsxqd a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd_bzws x where a.id=x.id and a.version=x.item_version and a.code=x.item_code)  ");
		sql .setSql(sqlBF.toString());
		DataStore vdsSXQD = sql.executeQuery();
		tr.commitWithoutStart();
		
		//循环请求数据
		int i=0;
		String id="", type="", org_name="", inner_code="", name="", item_code="", item_version="";
		String urlPost = "";
		for(DataObject obj : vdsSXQD) {
			id = obj.getString("id", "");
			type = obj.getString("type", "");
			org_name = obj.getString("org_name", "");
			inner_code = obj.getString("inner_code", "");
			name = obj.getString("name", "");
			item_code = obj.getString("item_code", "");
			item_version = obj.getString("item_version", "");
			System.out.println("正在处理第"+ String.valueOf(++i) +"条事项:"+name);
			
			String httpStr = "";
			urlPost = "http://221.214.94.36:81/sxk/mng/project/factor/paper/query?"+"item_code="+item_code+"&item_version="+item_version;
			Map params=new HashMap();
			params.put("Accept", "application/json, text/javascript, */*; q=0.01");
			params.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			params.put("X-Requested-With", "XMLHttpRequest");
			params.put("Referer", "http://221.214.94.36:81/sxk/mng/project/change/info/index?v=1555583490723#");
			params.put("Accept-Language", "zh-CN");
			params.put("Accept-Encoding", "gzip, deflate");
			params.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)");
			params.put("Host", "221.214.94.36:81");
			params.put("Content-Length", "62");
			params.put("DNT", "1");
			params.put("Connection", "Keep-Alive");
			params.put("Cache-Control", "no-cache");
			//params.put("Cookie", "JSESSIONID=20984A6BF386E030A32E93E1E43ACA3E; webfinal.session.errorCount=0");
		//	params.put("", "");
			params.put("_search", "false");
			params.put("nd", "1555585140585");
			params.put("rows", "1000");
			params.put("page", "1");
			params.put("sidx", "");
			params.put("sord", "asc");
	        BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "16932DBF68B73FE6C4980F92628F5D5C");
	        cookie.setVersion(0);
	        cookie.setDomain("221.214.94.36");
	        cookie.setPath("/sxk/mng/project/factor/paper/query");
	        httpStr = doPost(urlPost, params, cookie, true);
	        if("302".equals(httpStr)) {
	        	System.out.println("302重定向");
	        	continue;
	        }else if("error".equals(httpStr)){
	        	System.out.println("error");
	        	continue;
	        }else {
	        	DataObject vdo = DataObject.parseJSON(httpStr);
//	        	Gson gson = new Gson();
//	    		Map map = gson.fromJson(httpStr, Map.class);
	        	int page = vdo.getInt("page");
	        	int records = vdo.getInt("records");
	        	int total = vdo.getInt("total");
	        	DataStore dsRows = vdo.getDataStore("rows");
	        	DataObject cell_i = new DataObject();
	        	
	        	String name_i="", description="", filename="", remark="", sn="", 
	        		   ext="", auth_level="", validate_time="", rownum_="", validate_time_unit="", 
	        		   url="", flag="", type_i="", code="";
	        	 
	        	//事务
	        	System.out.println("getXmBzwsList()---->start");
	    		GlobalNames.CONFIGINWAR = "true";
	    		FormalRunDB.setFormalRunDB(false);//正式库
//	    		DebugModeConfig.setDebugMode(false);//非debug模式
	    		tr = TransactionManager.getTransaction();
	    		tr.begin();
//	    		tr.rollback();
//	    		tr.commitWithoutStart();
	    		int clxh=0;
	    		if(dsRows==null || dsRows.rowCount()==0) {
	    			index = 0;
        			sqlBF.setLength(0);
        			sqlBF.append(" INSERT INTO ga0001.tzxmsxqd_bzws( ");
        			sqlBF.append("             id, type, org_name, inner_code, name, cqsj, wsxh, filename, item_code, item_version) ");
        			sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ");
        			sql .setSql(sqlBF.toString());
        			sql.setString(++index, id);
        			sql.setString(++index, type);
        			sql.setString(++index, org_name);
        			sql.setString(++index, inner_code);
        			sql.setString(++index, name);
        			
        			sql.setDateTime(++index, DateUtil.getDBTime());
        			sql.setString(++index, String.valueOf(0));
        			sql.setString(++index, "无");
        			sql.setString(++index, item_code);
        			sql.setString(++index, item_version);
        			
        			sql.executeUpdate();
	    		}
	        	for(DataObject obj_i : dsRows) {
	        		clxh+=1;
	        		cell_i =  DataObject.parseJSON(obj_i.getString("cell"));
	        		
	        		name_i = ("null".equals(String.valueOf(cell_i.getObject("name"))))?"":String.valueOf(cell_i.getObject("name"));
	        		description = ("null".equals(String.valueOf(cell_i.getObject("description"))))?"":String.valueOf(cell_i.getObject("description"));
	        		filename = ("null".equals(String.valueOf(cell_i.getObject("filename"))))?"":String.valueOf(cell_i.getObject("filename"));
	        		remark = ("null".equals(String.valueOf(cell_i.getObject("remark"))))?"":String.valueOf(cell_i.getObject("remark"));
	        		sn = ("null".equals(String.valueOf(cell_i.getObject("sn"))))?"":String.valueOf(cell_i.getObject("sn"));

	        		ext = ("null".equals(String.valueOf(cell_i.getObject("ext"))))?"":String.valueOf(cell_i.getObject("ext"));
	        		auth_level = ("null".equals(String.valueOf(cell_i.getObject("auth_level"))))?"":String.valueOf(cell_i.getObject("auth_level"));
	        		validate_time = ("null".equals(String.valueOf(cell_i.getObject("validate_time"))))?"":String.valueOf(cell_i.getObject("validate_time"));
	        		rownum_ = ("null".equals(String.valueOf(cell_i.getObject("rownum_"))))?"":String.valueOf(cell_i.getObject("rownum_"));
	        		validate_time_unit = ("null".equals(String.valueOf(cell_i.getObject("validate_time_unit"))))?"":String.valueOf(cell_i.getObject("validate_time_unit"));

	        		url = ("null".equals(String.valueOf(cell_i.getObject("url"))))?"":String.valueOf(cell_i.getObject("url"));
	        		flag = ("null".equals(String.valueOf(cell_i.getObject("flag"))))?"":String.valueOf(cell_i.getObject("flag"));
	        		type_i = ("null".equals(String.valueOf(cell_i.getObject("type"))))?"":String.valueOf(cell_i.getObject("type"));
	        		code = ("null".equals(String.valueOf(cell_i.getObject("code"))))?"":String.valueOf(cell_i.getObject("code"));

    				index = 0;
        			sqlBF.setLength(0);
        			sqlBF.append(" INSERT INTO ga0001.tzxmsxqd_bzws( ");
        			sqlBF.append("             id, type, org_name, inner_code, name, cqsj, wsxh, name_i, description, ");
        			sqlBF.append("             filename, remark, sn, ext, auth_level, validate_time, rownum_, ");
        			sqlBF.append("             validate_time_unit, url, flag, type_i, code, item_code, item_version) ");
        			sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ?) ");
        			sql .setSql(sqlBF.toString());
        			sql.setString(++index, id);
        			sql.setString(++index, type);
        			sql.setString(++index, org_name);
        			sql.setString(++index, inner_code);
        			sql.setString(++index, name);
        			
        			sql.setDateTime(++index, DateUtil.getDBTime());
        			sql.setString(++index, String.valueOf(clxh));
        			sql.setString(++index, name_i);
        			sql.setString(++index, description);
        			sql.setString(++index, filename);
        			
        			sql.setString(++index, remark);
        			sql.setString(++index, sn);
        			sql.setString(++index, ext);
        			sql.setString(++index, auth_level);
        			sql.setString(++index, validate_time);
        			
        			sql.setString(++index, rownum_);
        			sql.setString(++index, validate_time_unit);
        			sql.setString(++index, url);
        			sql.setString(++index, flag);
        			sql.setString(++index, type_i);
        			
        			sql.setString(++index, code);
        			sql.setString(++index, item_code);
        			sql.setString(++index, item_version);

        			sql.executeUpdate();
	    			

	        	}
	        	tr.commitWithoutStart();
	        	System.out.println("getXmBzwsList()---->end");
	        }
		}
		
		System.out.println("getXmBzwsList()---->overAll");
		return null;
	}
	
	/**
	 * 抽取申请材料
	 * @description 
	 * @author 徐本锡
	 * @date 2019年4月18日
	 * @version V1.0
	 * @throws AppException 
	 */
	public static String getXmSqclList() throws AppException {
		/*		
		http://221.214.94.36:81/sxk/main
		
		123456
		*/

		GlobalNames.CONFIGINWAR = "true";
		FormalRunDB.setFormalRunDB(false);//正式库
//		DebugModeConfig.setDebugMode(false);//非debug模式
		Transaction tr = TransactionManager.getTransaction();
		tr.begin();
		
		//删除版本号不同的材料
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" delete from ga0001.tzxmsxqd_sqcl a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd x where a.id=x.id and a.item_code=x.code and a.item_version=x.version) ");
		sql .setSql(sqlBF.toString());
		sql.executeUpdate();
		
		//查询需要爬取的项目
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" select a.id, a.type, a.org_name, a.inner_code, a.name, a.code item_code, a.version item_version ");
		sqlBF.append("   from ga0001.tzxmsxqd a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd_sqcl x where a.id=x.id and a.version=x.item_version and a.code=x.item_code)  ");
		sql .setSql(sqlBF.toString());
		DataStore vdsSXQD = sql.executeQuery();
		tr.commitWithoutStart();
		
		//循环请求数据
		int i=0;
		String id="", type="", org_name="", inner_code="", name="", item_code="", item_version="";
		String urlPost = "";
		for(DataObject obj : vdsSXQD) {
			id = obj.getString("id", "");
			type = obj.getString("type", "");
			org_name = obj.getString("org_name", "");
			inner_code = obj.getString("inner_code", "");
			name = obj.getString("name", "");
			item_code = obj.getString("item_code", "");
			item_version = obj.getString("item_version", "");
			System.out.println("正在处理第"+ String.valueOf(++i) +"条事项:"+name);
			
			String httpStr = "";
			urlPost = "http://221.214.94.36:81/sxk/mng/project/factor/material/query?"+"item_code="+item_code+"&item_version="+item_version;
			Map params=new HashMap();
			params.put("Accept", "application/json, text/javascript, */*; q=0.01");
			params.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			params.put("X-Requested-With", "XMLHttpRequest");
			params.put("Referer", "http://221.214.94.36:81/sxk/mng/project/change/info/index?v=1555566134232#");
			params.put("Accept-Language", "zh-CN");
			params.put("Accept-Encoding", "gzip, deflate");
			params.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)");
			params.put("Host", "221.214.94.36:81");
			params.put("Content-Length", "62");
			params.put("DNT", "1");
			params.put("Connection", "Keep-Alive");
			params.put("Cache-Control", "no-cache");
			//params.put("Cookie", "JSESSIONID=20984A6BF386E030A32E93E1E43ACA3E; webfinal.session.errorCount=0");
		//	params.put("", "");
			params.put("_search", "false");
			params.put("nd", "1555571284464");
			params.put("rows", "1000");
			params.put("page", "1");
			params.put("sidx", "");
			params.put("sord", "asc");
	        BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "20984A6BF386E030A32E93E1E43ACA3E");
	        cookie.setVersion(0);
	        cookie.setDomain("221.214.94.36");
	        cookie.setPath("/sxk/mng/project/factor/material/query");
	        httpStr = doPost(urlPost, params, cookie, true);
	        if("302".equals(httpStr)) {
	        	System.out.println("302重定向");
	        	continue;
	        }else if("error".equals(httpStr)){
	        	System.out.println("error");
	        	continue;
	        }else {
	        	DataObject vdo = DataObject.parseJSON(httpStr);
//	        	Gson gson = new Gson();
//	    		Map map = gson.fromJson(httpStr, Map.class);
	        	int page = vdo.getInt("page");
	        	int records = vdo.getInt("records");
	        	int total = vdo.getInt("total");
	        	DataStore dsRows = vdo.getDataStore("rows");
	        	DataObject cell_i = new DataObject();
	        	String is_template="", what="", publisher="", remark="", how_transact="", 
	        			paper_material_format="", blank="", where_transact="", filling_explanation="", is_example="", 
	        			version="", template_name="", is_sample="", sort_order="", must="", 
	        			example="", url="", flag="", type_i="", explain="", 
	        			code="", accept_standard="", is_blank="", material_basis="", sample="",
	        			sample_name="", name_i="", original="", template="", filename="",
	        			example_name="", copy="", check_real="", origin="", folder_id="",
	        			rownum_="", blank_name="", constant_code="", item_code_i="", business_type="",
	        			sort_code="";
	        	 
	        	//事务
	        	System.out.println("getXmList()---->start");
	    		GlobalNames.CONFIGINWAR = "true";
	    		FormalRunDB.setFormalRunDB(false);//正式库
//	    		DebugModeConfig.setDebugMode(false);//非debug模式
	    		tr = TransactionManager.getTransaction();
	    		tr.begin();
//	    		tr.rollback();
//	    		tr.commitWithoutStart();
	    		int clxh=0;
	    		if(dsRows==null || dsRows.rowCount()==0) {
	    			index = 0;
        			sqlBF.setLength(0);
        			sqlBF.append(" INSERT INTO ga0001.tzxmsxqd_sqcl( ");
        			sqlBF.append("             id, clxh, type, org_name, inner_code, name, item_code, item_version, name_i ) ");
        			sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? ) ");
        			sql .setSql(sqlBF.toString());
        			sql.setString(++index, id);
        			sql.setString(++index, String.valueOf(0));
        			sql.setString(++index, type);
        			sql.setString(++index, org_name);
        			sql.setString(++index, inner_code);
        			
        			sql.setString(++index, name);
        			sql.setString(++index, item_code);
        			sql.setString(++index, item_version);
        			sql.setString(++index, "无");
        			
        			sql.executeUpdate();
	    		}
	        	for(DataObject obj_i : dsRows) {
	        		clxh+=1;
	        		cell_i =  DataObject.parseJSON(obj_i.getString("cell"));
	        		is_template = ("null".equals(String.valueOf(cell_i.getObject("is_template"))))?"":String.valueOf(cell_i.getObject("is_template"));
	        		what = ("null".equals(String.valueOf(cell_i.getObject("what"))))?"":String.valueOf(cell_i.getObject("what"));
	        		publisher = ("null".equals(String.valueOf(cell_i.getObject("publisher"))))?"":String.valueOf(cell_i.getObject("publisher"));
	        		remark = ("null".equals(String.valueOf(cell_i.getObject("remark"))))?"":String.valueOf(cell_i.getObject("remark"));
	        		how_transact = ("null".equals(String.valueOf(cell_i.getObject("how_transact"))))?"":String.valueOf(cell_i.getObject("how_transact"));

	        		paper_material_format = ("null".equals(String.valueOf(cell_i.getObject("paper_material_format"))))?"":String.valueOf(cell_i.getObject("paper_material_format"));
	        		blank = ("null".equals(String.valueOf(cell_i.getObject("blank"))))?"":String.valueOf(cell_i.getObject("blank"));
	        		where_transact = ("null".equals(String.valueOf(cell_i.getObject("where_transact"))))?"":String.valueOf(cell_i.getObject("where_transact"));
	        		filling_explanation = ("null".equals(String.valueOf(cell_i.getObject("filling_explanation"))))?"":String.valueOf(cell_i.getObject("filling_explanation"));
	        		is_example = ("null".equals(String.valueOf(cell_i.getObject("is_example"))))?"":String.valueOf(cell_i.getObject("is_example"));

	        		version = ("null".equals(String.valueOf(cell_i.getObject("version"))))?"":String.valueOf(cell_i.getObject("version"));
	        		template_name = ("null".equals(String.valueOf(cell_i.getObject("template_name"))))?"":String.valueOf(cell_i.getObject("template_name"));
	        		is_sample = ("null".equals(String.valueOf(cell_i.getObject("is_sample"))))?"":String.valueOf(cell_i.getObject("is_sample"));
	        		sort_order = ("null".equals(String.valueOf(cell_i.getObject("sort_order"))))?"":String.valueOf(cell_i.getObject("sort_order"));
	        		must = ("null".equals(String.valueOf(cell_i.getObject("must"))))?"":String.valueOf(cell_i.getObject("must"));
	        		
	        		example = ("null".equals(String.valueOf(cell_i.getObject("example"))))?"":String.valueOf(cell_i.getObject("example"));
	        		url = ("null".equals(String.valueOf(cell_i.getObject("url"))))?"":String.valueOf(cell_i.getObject("url"));
	        		flag = ("null".equals(String.valueOf(cell_i.getObject("flag"))))?"":String.valueOf(cell_i.getObject("flag"));
	        		type_i = ("null".equals(String.valueOf(cell_i.getObject("type"))))?"":String.valueOf(cell_i.getObject("type"));
	        		explain = ("null".equals(String.valueOf(cell_i.getObject("explain"))))?"":String.valueOf(cell_i.getObject("explain"));
	        		
	        		code = ("null".equals(String.valueOf(cell_i.getObject("code"))))?"":String.valueOf(cell_i.getObject("code"));
	        		accept_standard = ("null".equals(String.valueOf(cell_i.getObject("accept_standard"))))?"":String.valueOf(cell_i.getObject("accept_standard"));
	        		is_blank = ("null".equals(String.valueOf(cell_i.getObject("is_blank"))))?"":String.valueOf(cell_i.getObject("is_blank"));
	        		material_basis = ("null".equals(String.valueOf(cell_i.getObject("material_basis"))))?"":String.valueOf(cell_i.getObject("material_basis"));
	        		sample = ("null".equals(String.valueOf(cell_i.getObject("sample"))))?"":String.valueOf(cell_i.getObject("sample"));

	        		sample_name = ("null".equals(String.valueOf(cell_i.getObject("sample_name"))))?"":String.valueOf(cell_i.getObject("sample_name"));
	        		name_i = ("null".equals(String.valueOf(cell_i.getObject("name"))))?"":String.valueOf(cell_i.getObject("name"));
	        		original = ("null".equals(String.valueOf(cell_i.getObject("original"))))?"":String.valueOf(cell_i.getObject("original"));
	        		template = ("null".equals(String.valueOf(cell_i.getObject("template"))))?"":String.valueOf(cell_i.getObject("template"));
	        		filename = ("null".equals(String.valueOf(cell_i.getObject("filename"))))?"":String.valueOf(cell_i.getObject("filename"));
	        		
	        		example_name = ("null".equals(String.valueOf(cell_i.getObject("example_name"))))?"":String.valueOf(cell_i.getObject("example_name"));
	        		copy = ("null".equals(String.valueOf(cell_i.getObject("copy"))))?"":String.valueOf(cell_i.getObject("copy"));
	        		check_real = ("null".equals(String.valueOf(cell_i.getObject("check_real"))))?"":String.valueOf(cell_i.getObject("check_real"));
	        		origin = ("null".equals(String.valueOf(cell_i.getObject("origin"))))?"":String.valueOf(cell_i.getObject("origin"));
	        		folder_id = ("null".equals(String.valueOf(cell_i.getObject("folder_id"))))?"":String.valueOf(cell_i.getObject("folder_id"));

	        		rownum_ = ("null".equals(String.valueOf(cell_i.getObject("rownum_"))))?"":String.valueOf(cell_i.getObject("rownum_"));
	        		blank_name = ("null".equals(String.valueOf(cell_i.getObject("blank_name"))))?"":String.valueOf(cell_i.getObject("blank_name"));
	        		constant_code = ("null".equals(String.valueOf(cell_i.getObject("constant_code"))))?"":String.valueOf(cell_i.getObject("constant_code"));
	        		item_code_i = ("null".equals(String.valueOf(cell_i.getObject("item_code"))))?"":String.valueOf(cell_i.getObject("item_code"));
	        		business_type = ("null".equals(String.valueOf(cell_i.getObject("business_type"))))?"":String.valueOf(cell_i.getObject("business_type"));
	        		
	        		sort_code = ("null".equals(String.valueOf(cell_i.getObject("sort_code"))))?"":String.valueOf(cell_i.getObject("sort_code"));

    				index = 0;
        			sqlBF.setLength(0);
        			sqlBF.append(" INSERT INTO ga0001.tzxmsxqd_sqcl( ");
        			sqlBF.append("             id, clxh, type, org_name, inner_code, name, item_code, item_version, ");
        			sqlBF.append("             is_template, what, publisher, remark, how_transact, paper_material_format, ");
        			sqlBF.append("             blank, where_transact, filling_explanation, is_example, template_name, ");
        			sqlBF.append("             is_sample, sort_order, must, example, url, flag, explain, code, ");
        			sqlBF.append("             accept_standard, is_blank, material_basis, sample, sample_name, ");
        			sqlBF.append("             original, template, filename, example_name, copy, check_real, ");
        			sqlBF.append("             origin, folder_id, rownum_, blank_name, constant_code, business_type, ");
        			sqlBF.append("             sort_code, type_i, name_i, item_code_i, version) ");
        			sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?) ");
        			sql .setSql(sqlBF.toString());
        			sql.setString(++index, id);
        			sql.setString(++index, String.valueOf(clxh));
        			sql.setString(++index, type);
        			sql.setString(++index, org_name);
        			sql.setString(++index, inner_code);
        			
        			sql.setString(++index, name);
        			sql.setString(++index, item_code);
        			sql.setString(++index, item_version);
        			sql.setString(++index, is_template);
        			sql.setString(++index, what);
        			
        			sql.setString(++index, publisher);
        			sql.setString(++index, remark);
        			sql.setString(++index, how_transact);
        			sql.setString(++index, paper_material_format);
        			sql.setString(++index, blank);
        			
        			sql.setString(++index, where_transact);
        			sql.setString(++index, filling_explanation);
        			sql.setString(++index, is_example);
        			sql.setString(++index, template_name);
        			sql.setString(++index, is_sample);
        			
        			sql.setString(++index, sort_order);
        			sql.setString(++index, must);
        			sql.setString(++index, example);
        			sql.setString(++index, url);
        			sql.setString(++index, flag);
        			
        			sql.setString(++index, explain);
        			sql.setString(++index, code);
        			sql.setString(++index, accept_standard);
        			sql.setString(++index, is_blank);
        			sql.setString(++index, material_basis);
        			
        			sql.setString(++index, sample);
        			sql.setString(++index, sample_name);
        			sql.setString(++index, original);
        			sql.setString(++index, template);
        			sql.setString(++index, filename);
        			
        			sql.setString(++index, example_name);
        			sql.setString(++index, copy);
        			sql.setString(++index, check_real);
        			sql.setString(++index, origin);
        			sql.setString(++index, folder_id);
        			
        			sql.setString(++index, rownum_);
        			sql.setString(++index, blank_name);
        			sql.setString(++index, constant_code);
        			sql.setString(++index, business_type);
        			sql.setString(++index, sort_code);
        			
        			sql.setString(++index, type_i);
        			sql.setString(++index, name_i);
        			sql.setString(++index, item_code_i);
        			sql.setString(++index, version);
        			sql.executeUpdate();
	    			

	        	}
	        	tr.commitWithoutStart();
	        	System.out.println("getXmSqclList()---->end");
	        }
		}
		
		System.out.println("getXmSqclList()---->overAll");
		return null;
	}
	/**
	 * httpGet抽取基本要素
	 * 
	 * @description
	 * @author 徐本锡
	 * @date 2019年4月16日
	 * @version V1.0
	 * @throws DocumentException 
	 */
	public static void doGet_jbys() throws AppException {
		HttpResponse httpResponse = null;
		HttpClient httpClient = new DefaultHttpClient();
		
		//查询事项清单列表
		GlobalNames.CONFIGINWAR = "true";
		FormalRunDB.setFormalRunDB(false);//正式库
//		DebugModeConfig.setDebugMode(false);//非debug模式
		Transaction tr = TransactionManager.getTransaction();
		tr.begin();
		index = 0;
		sqlBF.setLength(0);
		sqlBF.append(" select a.id, a.type, a.org_name, a.inner_code, a.name ");
		sqlBF.append("   from  ga0001.tzxmsxqd a ");
		sqlBF.append("  where not exists (select 1 from ga0001.tzxmsxqd_jbys x where a.id=x.id)  ");
		sql .setSql(sqlBF.toString());
		DataStore vdsSXQD = sql.executeQuery();
		tr.commitWithoutStart();
		
		//循环请求数据
		int i=0;
		String id="", type="", org_name="", inner_code="", name="";
		String url = "";
		for(DataObject obj : vdsSXQD) {
			id = obj.getString("id", "");
			type = obj.getString("type", "");
			org_name = obj.getString("org_name", "");
			inner_code = obj.getString("inner_code", "");
			name = obj.getString("name", "");
			System.out.println("正在处理第"+ String.valueOf(++i) +"条事项:"+name);
			url = "http://221.214.94.36:81/sxk/main/power/"+type+"/"+id+"?_=1555484662484";
			HttpGet get = new HttpGet(url);
			
			GlobalNames.CONFIGINWAR = "true";
			FormalRunDB.setFormalRunDB(false);//正式库
//			DebugModeConfig.setDebugMode(false);//非debug模式
			tr = TransactionManager.getTransaction();
			tr.begin();
			
			index = 0;
			sqlBF.setLength(0);
			sqlBF.append("delete from ga0001.tzxmsxqd_jbys where id=? ");
			sql .setSql(sqlBF.toString());
			sql.setString(++index, id);
			sql.executeUpdate();
			
			StringBuffer keyBF = new StringBuffer();
			StringBuffer valueBF = new StringBuffer();
			keyBF.append(" insert into ga0001.tzxmsxqd_jbys (id, type, org_name, inner_code, name, cqsj ");
			valueBF.append("    VALUES (?, ?, ?, ?, ?, ? ");
			
			try {
				httpResponse = httpClient.execute(get, localContext);
				HttpEntity httpEntity = httpResponse.getEntity();
				String httpResult = EntityUtils.toString(httpEntity);
				Document document = Jsoup.parse(httpResult);
				//Elements elementsJBYS = document.getElementsByClass("pull-left");
				Elements elementsJBYSList = document.getElementsByClass("item-body");
				
				for (Element element : elementsJBYSList) {
					Elements elementsKEY = element.getElementsByClass("item-left");
					Elements elementsVALUE = element.getElementsByClass("item-right");
					String key = elementsKEY.text().trim();
					String value = elementsVALUE.text().trim();
					keyBF.append(",\""+key+"\"");
					valueBF.append(", '"+value+"'");
				}
				keyBF.append(") ");
				valueBF.append(") ");
				index = 0;
				sqlBF.setLength(0);
				sqlBF.append(keyBF).append(valueBF);
				sql .setSql(sqlBF.toString());
				sql.setString(++index, id);
				sql.setString(++index, type);
				sql.setString(++index, org_name);
				sql.setString(++index, inner_code);
				sql.setString(++index, name);
				sql.setDateTime(++index, DateUtil.getDBTime());
				sql.executeUpdate();
				tr.commitWithoutStart();
			} catch (IOException e) {
				tr.rollback();
				e.printStackTrace();
			}
		}
		
	}

	/**
	 * 抽取项目列表
	 * @description 
	 * @author 徐本锡
	 * @date 2019年4月17日
	 * @version V1.0
	 * @throws AppException 
	 */
	public static String getXmList() throws AppException {
		/*		
		http://221.214.94.36:81/sxk/main
		
		123456
		*/
		String httpStr = "";
		String url = "http://221.214.94.36:81/sxk/mng/project/change/info/query";
		Map params=new HashMap();
		params.put("Accept", "application/json, text/javascript, */*; q=0.01");
		params.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		params.put("X-Requested-With", "XMLHttpRequest");
		params.put("Referer", "http://221.214.94.36:81/sxk/mng/project/change/info/index?v=1555459803922");
		params.put("Accept-Language", "zh-CN");
		params.put("Accept-Encoding", "gzip, deflate");
		params.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)");
		params.put("Host", "221.214.94.36:81");
		params.put("Content-Length", "65");
		params.put("DNT", "1");
		params.put("Connection", "Keep-Alive");
		params.put("Cache-Control", "no-cache");
		//params.put("Cookie", "td_cookie=18446744069731352277; JSESSIONID=2BA9A59C8E68D0633EC3678BDFFAC749; webfinal.session.errorCount=0; webfinal.session.id=51f435c7-5f0c-4e6c-a883-e2e0d9f43c2b");
	//	params.put("", "");
		params.put("_search", "false");
		params.put("nd", "1555402726472");
		params.put("rows", "300");
		params.put("page", "1");
		params.put("sidx", "CODE");
		params.put("sord", "desc");
		
        BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "58DEDE9E70972800E2DA909F3445661E");
        cookie.setVersion(0);
        cookie.setDomain("221.214.94.36");
        cookie.setPath("/sxk/mng/project/change/info/query");
		
        httpStr = doPost(url, params, cookie, true);
        if("302".equals(httpStr)) {
        	
        }else if("error".equals(httpStr)){
        	
        }else {
        	DataObject vdo = DataObject.parseJSON(httpStr);
//        	Gson gson = new Gson();
//    		Map map = gson.fromJson(httpStr, Map.class);
        	int page = vdo.getInt("page");
        	int records = vdo.getInt("records");
        	int total = vdo.getInt("total");
        	DataStore dsRows = vdo.getDataStore("rows");
        	DataObject cell_i = new DataObject();
        	String hid="",hversion="",org_name="",region_code="",property="",state="",inner_code="",name="",rownum_="",status="",
        		   code="",region_name="",f_name="",org_code="",folder_code="",version="",handle_name="",id="",hstatus="",htype="",
        		   hstate="",type="";	
        	 
        	//事务
        	System.out.println("getXmList()---->start");
    		GlobalNames.CONFIGINWAR = "true";
    		FormalRunDB.setFormalRunDB(false);//正式库
//    		DebugModeConfig.setDebugMode(false);//非debug模式
    		Transaction tr = TransactionManager.getTransaction();
    		tr.begin();
//    		tr.rollback();
//    		tr.commitWithoutStart();
        	for(DataObject obj : dsRows) {
        		cell_i =  DataObject.parseJSON(obj.getString("cell"));
        		hid = ("null".equals(String.valueOf(cell_i.getObject("hid"))))?"":String.valueOf(cell_i.getObject("hid"));
        		hversion = ("null".equals(String.valueOf(cell_i.getObject("hversion"))))?"":String.valueOf(cell_i.getObject("hversion"));
        		org_name = ("null".equals(String.valueOf(cell_i.getObject("org_name"))))?"":String.valueOf(cell_i.getObject("org_name"));
        		region_code = ("null".equals(String.valueOf(cell_i.getObject("region_code"))))?"":String.valueOf(cell_i.getObject("region_code"));
        		property = ("null".equals(String.valueOf(cell_i.getObject("property"))))?"":String.valueOf(cell_i.getObject("property"));

        		state = ("null".equals(String.valueOf(cell_i.getObject("state"))))?"":String.valueOf(cell_i.getObject("state"));
        		inner_code = ("null".equals(String.valueOf(cell_i.getObject("inner_code"))))?"":String.valueOf(cell_i.getObject("inner_code"));
        		name = ("null".equals(String.valueOf(cell_i.getObject("name"))))?"":String.valueOf(cell_i.getObject("name"));
        		rownum_ = ("null".equals(String.valueOf(cell_i.getObject("rownum_"))))?"":String.valueOf(cell_i.getObject("rownum_"));
        		status = ("null".equals(String.valueOf(cell_i.getObject("status"))))?"":String.valueOf(cell_i.getObject("status"));
        		
        		code = ("null".equals(String.valueOf(cell_i.getObject("code"))))?"":String.valueOf(cell_i.getObject("code"));
        		region_name = ("null".equals(String.valueOf(cell_i.getObject("region_name"))))?"":String.valueOf(cell_i.getObject("region_name"));
        		f_name = ("null".equals(String.valueOf(cell_i.getObject("f_name"))))?"":String.valueOf(cell_i.getObject("f_name"));
        		org_code = ("null".equals(String.valueOf(cell_i.getObject("org_code"))))?"":String.valueOf(cell_i.getObject("org_code"));
        		folder_code = ("null".equals(String.valueOf(cell_i.getObject("folder_code"))))?"":String.valueOf(cell_i.getObject("folder_code"));
        		
        		version = ("null".equals(String.valueOf(cell_i.getObject("version"))))?"":String.valueOf(cell_i.getObject("version"));
        		handle_name = ("null".equals(String.valueOf(cell_i.getObject("handle_name"))))?"":String.valueOf(cell_i.getObject("handle_name"));
        		id = ("null".equals(String.valueOf(cell_i.getObject("id"))))?"":String.valueOf(cell_i.getObject("id"));
        		hstatus = ("null".equals(String.valueOf(cell_i.getObject("hstatus"))))?"":String.valueOf(cell_i.getObject("hstatus"));
        		htype = ("null".equals(String.valueOf(cell_i.getObject("htype"))))?"":String.valueOf(cell_i.getObject("htype"));
        		
        		hstate = ("null".equals(String.valueOf(cell_i.getObject("hstate"))))?"":String.valueOf(cell_i.getObject("hstate"));
        		type = ("null".equals(String.valueOf(cell_i.getObject("type"))))?"":String.valueOf(cell_i.getObject("type"));
        		
        		index = 0;
    			sqlBF.setLength(0);
    			sqlBF.append(" UPDATE ga0001.tzxmsxqd ");
    			sqlBF.append("    SET hid=?, hversion=?, org_name=?, region_code=?, property=?, state=?, ");
    			sqlBF.append("        inner_code=?, name=?, rownum_=?, status=?, code=?, region_name=?, ");
    			sqlBF.append("        f_name=?, org_code=?, folder_code=?, version=?, handle_name=?, ");
    			sqlBF.append("        hstatus=?, htype=?, hstate=?, type=?");
    			sqlBF.append("  WHERE id=? ");
    			sql .setSql(sqlBF.toString());
    			sql.setString(++index, hid);
    			sql.setString(++index, hversion);
    			sql.setString(++index, org_name);
    			sql.setString(++index, region_code);
    			sql.setString(++index, property);
    			
    			sql.setString(++index, state);
    			sql.setString(++index, inner_code);
    			sql.setString(++index, name);
    			sql.setString(++index, rownum_);
    			sql.setString(++index, status);
    			
    			sql.setString(++index, code);
    			sql.setString(++index, region_name);
    			sql.setString(++index, f_name);
    			sql.setString(++index, org_code);
    			sql.setString(++index, folder_code);
    			
    			sql.setString(++index, version);
    			sql.setString(++index, handle_name);
    			sql.setString(++index, hstatus);
    			sql.setString(++index, htype);
    			sql.setString(++index, hstate);
    			
    			sql.setString(++index, type);
    			sql.setString(++index, id);
    			int row = sql.executeUpdate();
    			if(row==0) {
    				index = 0;
        			sqlBF.setLength(0);
        			sqlBF.append(" INSERT INTO ga0001.tzxmsxqd( ");
        			sqlBF.append("             hid, hversion, org_name, region_code, property, state, inner_code, ");
        			sqlBF.append("             name, rownum_, status, code, region_name, f_name, org_code, folder_code, ");
        			sqlBF.append("             version, handle_name, id, hstatus, htype, hstate, type) ");
        			sqlBF.append("     VALUES (?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ?, ?, ");
        			sqlBF.append("             ?, ?, ?, ?, ?, ?, ?) ");
        			sql .setSql(sqlBF.toString());
        			sql.setString(++index, hid);
        			sql.setString(++index, hversion);
        			sql.setString(++index, org_name);
        			sql.setString(++index, region_code);
        			sql.setString(++index, property);
        			
        			sql.setString(++index, state);
        			sql.setString(++index, inner_code);
        			sql.setString(++index, name);
        			sql.setString(++index, rownum_);
        			sql.setString(++index, status);
        			
        			sql.setString(++index, code);
        			sql.setString(++index, region_name);
        			sql.setString(++index, f_name);
        			sql.setString(++index, org_code);
        			sql.setString(++index, folder_code);
        			
        			sql.setString(++index, version);
        			sql.setString(++index, handle_name);
        			sql.setString(++index, id);
        			sql.setString(++index, hstatus);
        			sql.setString(++index, htype);
        			
        			sql.setString(++index, hstate);
        			sql.setString(++index, type);
        			sql.executeUpdate();
    			}

        	}
        	tr.commitWithoutStart();
        	System.out.println("getXmList()---->end");
        }
		return httpStr;
	}
	/**
	/**
	 * 发送 POST 请求(HTTP),参数为 Key-Value 形式
	 *
	 * @param apiUrl API接口URL
	 * @param params 参数map
	 * @return
	 */
	public static String doPost(String url, Map params,  BasicClientCookie cookie, boolean withCookie) {
		HttpResponse response = null;
		HttpClient httpClient = new DefaultHttpClient();
		String httpStr = null;
		HttpPost httpPost = new HttpPost(url);

		if(withCookie) {
			BasicCookieStore cookieStore = new BasicCookieStore();
	        cookieStore.addCookie(cookie);
	        //带有cookie的httpclient
	        httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
	      //httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
		}
        
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).setConnectionRequestTimeout(60000).build();
        
		try {
			httpPost.setConfig(requestConfig);
			List pairList = new ArrayList<>(params.size());
			for (Map.Entry entry : params.entrySet()) {
				NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
				pairList.add(pair);
			}

			httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
			
			response = httpClient.execute(httpPost);
			//System.out.println(response.toString());
			HttpEntity entity = response.getEntity();
			
			int code = response.getStatusLine().getStatusCode();
			
			//重定向
			if(code==302){
/*				//释放
				httpPost.abort();
				httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.MICROSECONDS);
				
				HttpGet locationUrl = new HttpGet(response.getLastHeader("location").getValue());
				response = httpClient.execute(locationUrl);
				System.out.println(response.toString());
				entity = response.getEntity();*/
				//System.out.println("302");
				httpStr="302";
			}else {
				httpStr = EntityUtils.toString(entity, "UTF-8");
			}
			
		} catch (IOException e) {
			httpStr="error";
			e.printStackTrace();
		} finally {
			if (response != null) {
				try {
					EntityUtils.consume(response.getEntity());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		//System.out.println(httpStr);
		return httpStr;
	}
	
}

你可能感兴趣的:(Java,HttpClient,post请求,get请求,抓取网络数据)