/// <summary> /// 获取资源编录列表-机动车合格证申请界面 /// </summary> /// <param name="strLoginUrl"></param> /// <param name="strTargerUrl2"></param> public DataTable GetHtmlSourceListHGZ(string strTargerUrl, String page) { DataTable data = new DataTable(); string strContent = Tool.ReadHTML(strTargerUrl); if (!string.IsNullOrEmpty(strContent)) { ConvertHGZ convertHGZ = new ConvertHGZ(); var dataList = convertHGZ.getListHGZ(strContent, page); //按时间返回信息 if (!string.IsNullOrEmpty(param)) { data = dataList.Clone(); DataRow[] drs = dataList.Select(param); if (drs != null && drs.Count() > 0) { data = drs.CopyToDataTable(); } } else { data = dataList; } } return(data); }
/// <summary> /// 资源编录列表-机动车合格证申请界面 /// </summary> public void GetHtmlSourceListHGZ() { ConvertHGZ convertHGZ = new ConvertHGZ(); int pageNum = 1; while (true) { string strTargerUrl = string.Format("http://resource.autoidc.cn/pages/list.aspx?RESOURCEKEY=HGZ&PAGEID={0}", pageNum); string strContex = ReadHTML(strTargerUrl); var num = convertHGZ.getPageNumHGZ(strContex); var data = convertHGZ.getListHGZ(strContex, pageNum.ToString()); LogManager.Log("MainLog", "HGZ", pageNum.ToString()); //InsertHGZ insertHGZ = new InsertHGZ(); //insertHGZ.InsertListHGZ(data); for (int i = 0; i < data.Rows.Count; i++) { // 资源明细-机动车合格证申请界面 string strTargerUrlDetailsHGZ = string.Format("http://resource.autoidc.cn/pages/details.aspx?RESOURCEKEY=HGZ&RESOURCEID={0}", "HIDC00000000000420491536"); GetHtmlSourceDetailsHGZ(data.Rows[i]["APP_TIME"].ToString(), data.Rows[i]["APP_TYPE"].ToString(), strTargerUrlDetailsHGZ); LogManager.Log("MainLog", "HGZ", data.Rows[i]["SQBH"].ToString()); } pageNum++; if (num == pageNum) { break; } } }
/// <summary> /// 机动车合格证申请界面-详细信息 /// </summary> public void GetHtmlSourceDetailsHGZ(string appTime, string appType, string strTargerUrl) { string strContex = ReadHTML(strTargerUrl); ConvertHGZ convertHGZ = new ConvertHGZ(); //var data = convertHGZ.getDetailsHGZ(strContex); var data1 = convertHGZ.getDetailsHGZ(appTime, appType, strContex); InsertHGZ insertHGZ = new InsertHGZ(); //insertHGZ.InsertDetailsHGZ(data); insertHGZ.InsertDBHGZ(data1); //insertHGZ.InsertSingleDBHGZ(data1); //insertHGZ.InsertTvpDBHGZ(data1); }
/// <summary> /// 插入数据库 /// </summary> /// <param name="strLoginUrl"></param> /// <param name="strTargerUrl"></param> /// <param name="data">列表数据</param> public void InsertDataHGZ(string strTargerUrl, DataTable data, int page) { LogWrite(string.Format("{0} 正在抓取合格证详细信息第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), data.Rows.Count.ToString())); string strContex = string.Empty; string msg = string.Empty; int dataCount = data.Rows.Count; InsertHGZ insertHGZ = new InsertHGZ(); ConvertHGZ convertHGZ = new ConvertHGZ(); insertHGZ.InsertListHGZ(data); DataTable dtInsert = new DataTable(); int i = 0; try { for (i = 0; i < dataCount; i++) { if (IsStopped) { string id = data.Rows[i]["SQBH"].ToString().Trim(); string app_time = data.Rows[i]["APP_TIME"].ToString().Trim(); string app_type = data.Rows[i]["APP_TYPE"].ToString().Trim(); string strContent = Tool.ReadHTML(strTargerUrl + id); if (!string.IsNullOrEmpty(strContent)) { var dataDetails = convertHGZ.getDetailsHGZ(app_time, app_type, strContent); //try //{ // insertHGZ.InsertDBHGZ(dataDetails); //} //catch (ArgumentException ex) //{ // msg = string.Format("{0} 正在抓取第{1}页,插入合格证详细信息数据时出错:i={2},id={3},{4}", DateTime.Now.ToString("G"), page.ToString(), i.ToString(),id, ex.InnerException.Message); // LogWrite(msg); //} if (i == 0) { dtInsert = dataDetails; } else { DataRow dr = dataDetails.Rows[0]; dtInsert.Rows.Add(dr.ItemArray); } } } } if (IsStopped) { insertHGZ.InsertDBHGZ(dtInsert); LogWrite(string.Format("{0} 插入合格证详细信息第{1}页,共{2}条数据", DateTime.Now.ToString("G"), (page).ToString(), dtInsert.Rows.Count.ToString())); } } catch (ArgumentException ex) { msg = string.Format("{0} 正在抓取第{1}页,插入合格证详细信息数据时出错:i={2},{3}", DateTime.Now.ToString("G"), page.ToString(), i.ToString(), ex.InnerException.Message); LogWrite(msg); } //msg = string.Format("{0} 正在抓取第{1}页,插入详细信息{2}条数据", DateTime.Now.ToString("G"), page.ToString(), dataCount.ToString()); //LogWrite(msg); }