/// <summary> /// 获取办公地址并保存分支机构信息 /// </summary> /// <param name="html"></param> /// <param name="url"></param> /// <returns></returns> private string GetOffAddress(string html, string url, CorpInfo info) { string viewState = string.Empty; string eventValidation = string.Empty; string cookiestr = string.Empty; viewState = ToolWeb.GetAspNetViewState(html); eventValidation = ToolWeb.GetAspNetEventValidation(html); string returnValue = string.Empty; int pageInt = 1; NameValueCollection nvc = ToolWeb.GetNameValueCollection(new string[] { "ctl00$MainContent$ScriptManager1", "__EVENTTARGET", "__EVENTARGUMENT", "__VIEWSTATE", "__EVENTVALIDATION", "__ASYNCPOST" }, new string[] { "ctl00$MainContent$UpdatePanel1|ctl00$MainContent$step2", "ctl00$MainContent$step2", "", viewState, eventValidation, "true" }); string htmldtl = string.Empty; try { htmldtl = ToolWeb.GetHtmlByUrl(url, nvc, Encoding.UTF8, ref cookiestr); } catch { } Parser parser = new Parser(new Lexer(htmldtl)); NodeList dtlNode = parser.ExtractAllNodesThatMatch(new AndFilter(new TagNameFilter("table"), new HasAttributeFilter("class", "data-grid"))); if (dtlNode != null && dtlNode.Count > 0) { TableTag table = dtlNode[0] as TableTag; for (int i = 1; i < table.RowCount; i++) { string CorpName = string.Empty, CorpCode = string.Empty, Location = string.Empty, DtlAddress = string.Empty, PostalCode = string.Empty, ResInstitution = string.Empty, LinkMan = string.Empty, LinPhone = string.Empty, Fax = string.Empty, BusinessCode = string.Empty, RegDate = string.Empty, Email = string.Empty, SafetyCode = string.Empty, TotalReMan = string.Empty, TechReMan = string.Empty, SafeReMan = string.Empty, QualityReMan = string.Empty, Url = string.Empty, TotalSafetyCode = string.Empty, TechSafetyCode = string.Empty, QualitySafetyCode = string.Empty; TableRow tr = table.Rows[i]; Url = "http://113.108.219.40/intogd/Open/" + tr.Columns[0].GetATagHref(); CorpName = tr.Columns[0].ToNodePlainString(); TotalReMan = tr.Columns[2].ToNodePlainString(); TechReMan = tr.Columns[3].ToNodePlainString(); QualityReMan = tr.Columns[4].ToNodePlainString(); SafeReMan = tr.Columns[5].ToNodePlainString(); string dtlHtml = string.Empty; try { dtlHtml = ToolWeb.GetHtmlByUrl(Url, Encoding.UTF8); } catch { continue; } parser = new Parser(new Lexer(dtlHtml)); NodeList staffNode = parser.ExtractAllNodesThatMatch(new AndFilter(new TagNameFilter("table"), new HasAttributeFilter("width", "100%"))); if (staffNode != null && staffNode.Count > 1) { string ctx = string.Empty; TableTag dtlTable = staffNode[1] as TableTag; for (int k = 0; k < dtlTable.RowCount; k++) { for (int d = 0; d < dtlTable.Rows[k].ColumnCount; d++) { TableColumn col = dtlTable.Rows[k].Columns[d]; if (col.GetAttribute("class") == "td-left") { ctx += col.ToNodePlainString() + ":"; } else { ctx += col.ToNodePlainString() + "\r\n"; } } } if (string.IsNullOrEmpty(returnValue)) { returnValue = ctx.GetRegex("详细地址"); } CorpCode = ctx.GetRegex("组织机构代码"); Location = ctx.GetRegex("所在地"); DtlAddress = ctx.GetRegex("详细地址"); PostalCode = ctx.GetRegex("邮政编码"); ResInstitution = ctx.GetRegex("驻粤负责机构"); LinkMan = ctx.Replace(" ", "").GetRegex("联系人"); Fax = ctx.GetRegex("传真号码"); LinPhone = ctx.GetRegex("联系电话"); BusinessCode = ctx.GetRegex("营业执照注册号").Replace("分", ""); RegDate = ctx.GetRegex("设立时间").GetDateRegex(); Email = ctx.GetRegex("邮箱"); parser.Reset(); NodeList safeNode = parser.ExtractAllNodesThatMatch(new AndFilter(new TagNameFilter("table"), new HasAttributeFilter("class", "data-table"))); if (safeNode != null && safeNode.Count > 2) { TableTag safeTable = safeNode[2] as TableTag; string TotalSafetyCodeCtx = string.Empty; string TechSafetyCodeCtx = string.Empty; for (int k = 0; k < safeTable.RowCount; k++) { for (int d = 0; d < safeTable.Rows[k].ColumnCount; d++) { TableColumn col = safeTable.Rows[k].Columns[d]; if (d >= 2) { if (col.GetAttribute("class") == "td-left") { TechSafetyCodeCtx += col.ToNodePlainString() + ":"; } else { TechSafetyCodeCtx += col.ToNodePlainString() + "\r\n"; } } else { if (col.GetAttribute("class") == "td-left") { TotalSafetyCodeCtx += col.ToNodePlainString() + ":"; } else { TotalSafetyCodeCtx += col.ToNodePlainString() + "\r\n"; } } } } TotalSafetyCode = ToolHtml.GetRegexStringNot(TotalSafetyCodeCtx, new string[] { "安全生产考核合格证号(A证)" }); TechSafetyCode = ToolHtml.GetRegexStringNot(TechSafetyCodeCtx, new string[] { "安全生产考核合格证号(A证)" }); } if (safeNode != null && safeNode.Count > 4) { TableTag safeTable = safeNode[4] as TableTag; string SafetyCodeCtx = string.Empty; string QualitySafetyCodeCtx = string.Empty; for (int k = 0; k < safeTable.RowCount; k++) { for (int d = 0; d < safeTable.Rows[k].ColumnCount; d++) { TableColumn col = safeTable.Rows[k].Columns[d]; if (d >= 2) { if (col.GetAttribute("class") == "td-left") { QualitySafetyCodeCtx += col.ToNodePlainString() + ":"; } else { QualitySafetyCodeCtx += col.ToNodePlainString() + "\r\n"; } } else { if (col.GetAttribute("class") == "td-left") { SafetyCodeCtx += col.ToNodePlainString() + ":"; } else { SafetyCodeCtx += col.ToNodePlainString() + "\r\n"; } } } } SafetyCode = ToolHtml.GetRegexStringNot(SafetyCodeCtx, new string[] { "安全生产考核合格证号(A或B证)" }); QualitySafetyCode = ToolHtml.GetRegexStringNot(QualitySafetyCodeCtx, new string[] { "安全生产考核合格证号" });// QualitySafetyCodeCtx.GetRegex("安全生产考核合格证号"); } CorpInstitution entity = ToolDb.GenCorpInstitution("广东省", "广东地区", info.Id, CorpName, CorpCode, Location, DtlAddress, PostalCode, ResInstitution, LinkMan, LinPhone, Fax, BusinessCode, RegDate, Email, SafetyCode, TotalReMan, TechReMan, SafeReMan, QualityReMan, Url, TotalSafetyCode, TechSafetyCode, QualitySafetyCode); ToolDb.SaveEntity(entity, string.Empty); } } } return(returnValue); }