/// <summary> /// 获取证书编号对应详情 /// </summary> /// <param name="Certi_No"></param> private Dictionary <String, String> TUVLY_Details(String Certi_No) { Dictionary <String, String> dirs = new Dictionary <string, string>(); String html = "start"; String newcertino = Certi_No.Substring(1, Certi_No.Length - 1); try { HttpInfo info = new HttpInfo(); info.RequestUrl = String.Format(TUVLY_Details_Url, newcertino); while (!html.Contains(newcertino) || !html.Contains("Certificate No")) { //info.Ip = html = HttpMethod.HttpWork(info); Thread.Sleep(1); } if (html.Contains(newcertino)) { //处理数据 var strs = XpathMethod.GetMutResult(xpath_certi, html, 0); foreach (var str in strs) { if (XpathMethod.GetSingleResult(xpath_title, str, 1).Replace(": ", "") != "Certificate Holder") { dirs.Add(XpathMethod.GetSingleResult(xpath_title, str, 1).Replace(": ", ""), XpathMethod.GetSingleResult(xpath_details, str, 1).Replace("\n", "")); } } } } catch { } return(dirs); }
/// <summary> /// Xpath抽取匹配结果 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (String.IsNullOrEmpty(textEdit11.Text)) { Form4 form4 = new Form4("错误:Xpath表达式为空"); form4.Text = "错误"; form4.ShowDialog(); return; } richEditControl7.Text = ""; String text = checkEdit6.Checked ? Jhtml : html; //标识匹配或抽取 int flag = 1; if (checkEdit9.Checked) { flag = 0; } if (checkEdit10.Checked) { flag = 1; } if (checkEdit8.Checked) { try { var list = String.IsNullOrEmpty(textEdit12.Text) ? XpathMethod.GetMutResult(textEdit11.Text, text, flag) : XpathMethod.GetMutResult(textEdit11.Text, text, textEdit12.Text); richEditControl7.Text = String.Join("\n", list); } catch { richEditControl7.Text = "抽取失败"; } } else { try { richEditControl7.Text = String.IsNullOrEmpty(textEdit12.Text) ? XpathMethod.GetSingleResult(textEdit11.Text, text, flag) : XpathMethod.GetSingleResult(textEdit11.Text, text, textEdit12.Text); } catch { richEditControl7.Text = "抽取失败"; } } barStaticItem1.Caption = "当前状态:Xpath抽取完成"; }
private void button7_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBox15.Text)) { MessageBox.Show("Xpath为空"); return; } richTextBox2.Clear(); String text = checkBox6.Checked ? JsHtml : html; //标识匹配或抽取 int flag = 1; if (radioButton1.Checked) { flag = 0; } else if (radioButton2.Checked) { flag = 1; } if (checkBox5.Checked) { try { var list = String.IsNullOrEmpty(textBox16.Text) ? XpathMethod.GetMutResult(textBox15.Text, text, flag) : XpathMethod.GetMutResult(textBox15.Text, text, textBox16.Text); richTextBox2.Text = String.Join("\n", list); } catch { richTextBox2.Text = "抽取失败"; } } else { try { richTextBox2.Text = String.IsNullOrEmpty(textBox16.Text) ? XpathMethod.GetSingleResult(textBox15.Text, text, flag) : XpathMethod.GetSingleResult(textBox15.Text, text, textBox16.Text); } catch { richTextBox2.Text = "抽取失败"; } } }
private Dictionary <String, String> GetData(string html) { Dictionary <String, String> dirs = new Dictionary <string, string>(); var trs = XpathMethod.GetMutResult("//*[@id=\"certificatedetails\"]/table/tr", html, 0); foreach (var tr in trs) { var valign = XpathMethod.GetSingleResult("tr", tr, "valign"); if (valign.Trim().ToUpper().Equals("TOP")) { var name = XpathMethod.GetSingleResult("tr/td[1]", tr); var value = XpathMethod.GetSingleResult("tr/td[2]", tr); if (!name.Contains("ASTA BEAB Ref") && !name.Contains("Characteristics") && !name.Contains("Licenced Mark") && !name.Contains("Additional Info")) { dirs.Add(Fitlter(name, ":"), Fitlter(value)); } } } return(dirs); }
private void RunFunc(string xpathstr, string regstr, string proxyapi_url, bool timeflag, string ip) { GC.Collect(); UpRichTextBox uptxt = new UpRichTextBox(UpRichTxt); #region 请求前检查 if (String.IsNullOrEmpty(info.RequestUrl)) { Form4 form4 = new Form4("错误,请求地址不合法"); form4.Text = "错误"; form4.ShowDialog(); return; } #endregion #region 配置请求头 HttpInfo info_goto = CreateHttp(); if (!String.IsNullOrEmpty(ip)) { info_goto.Ip = ip; } #endregion double time = 0; Stopwatch sw = new Stopwatch(); if (timeflag) { sw.Start(); } String Html = HttpMethod.HttpWork(ref info_goto); if (sw.IsRunning) { sw.Stop(); time = sw.Elapsed.TotalSeconds; } String cookie = info_goto.Cookie.ConventToString(); String _ip = info_goto.Ip; #region 正则判断访问结果 if (!String.IsNullOrEmpty(regstr) && String.IsNullOrEmpty(xpathstr)) { String regtxt = RegexMethod.GetSingleResult(regstr, Html); String status = String.Empty; String txt = String.Empty; if (String.IsNullOrEmpty(regtxt)) { status = "访问失败"; } else { status = "访问成功"; } if (timeflag) { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n"; } else { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n"; } } else { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n"; } else { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n"; } } object[] arg = { txt }; this.Invoke(uptxt, arg); } #endregion #region Xpath判断访问结果 if (!String.IsNullOrEmpty(xpathstr) && String.IsNullOrEmpty(regstr)) { String regtxt = XpathMethod.GetSingleResult(xpathstr, Html); String status = String.Empty; String txt = String.Empty; if (String.IsNullOrEmpty(regtxt)) { status = "访问失败"; } else { status = "访问成功"; } if (timeflag) { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n"; } else { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n"; } } else { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n"; } else { txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n"; } } object[] arg = { txt }; this.Invoke(uptxt, arg); } #endregion #region 直接输出结果 if (String.IsNullOrEmpty(regstr) && String.IsNullOrEmpty(xpathstr)) { String txt = String.Empty; if (timeflag) { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n"; } else { txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n"; } } else { if (!String.IsNullOrEmpty(proxyapi_url)) { txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n"; } else { txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n"; } } object[] arg = { txt }; this.Invoke(uptxt, arg); } #endregion }