public VerifyCode GetVerifyCode() { try { if (string.IsNullOrWhiteSpace(jslCookies)) { jslCookies = GetWebBrowserCookies("http://www.miitbeian.gov.cn/getVerifyCode?71"); } if (string.IsNullOrWhiteSpace(JSESSIONID) && jslCookies.Contains("JSESSIONID=")) { JSESSIONID = jslCookies.Substring(jslCookies.IndexOf("JSESSIONID=") + 11).Trim(); } HttpItem item = new HttpItem() { URL = "http://www.miitbeian.gov.cn/getVerifyCode?71", Timeout = 30000, Accept = "image/webp,image/apng,image/*,*/*;q=0.8", Referer = "http://www.miitbeian.gov.cn/icp/publish/query/icpMemoInfo_showPage.action;jsessionid=" + JSESSIONID, ContentType = "image/jpeg", ResultType = ResultType.Byte, Cookie = jslCookies }; HttpResult rs = http.GetHtml(item); if (rs != null) { if (rs.StatusCode == (System.Net.HttpStatusCode) 521) { //反爬虫 //var username = webBrowser1.Document.InvokeScript("fnStringJM", objects); //var username = webBrowser1.Document.InvokeScript("A", new String[] { rs.Html }); jslCookies = string.Empty; JSESSIONID = string.Empty; } else if (rs.StatusCode == System.Net.HttpStatusCode.OK && rs.ResultByte != null && rs.ResultByte.Length > 1) { VerifyCode vc = new VerifyCode(); vc.Cookies = rs.Cookie; vc.ImgByte = rs.ResultByte; return(vc); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "获取验证码出现异常"); } return(null); }
public void Query() { Invoke((MethodInvoker) delegate { btnQuery.Enabled = false; }); try { string[] domains = txtDomains.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); if (domains != null && domains.Length > 0) { total = domains.Length; BeginInvoke((MethodInvoker) delegate { progressBar1.Maximum = total; }); for (int i = 0; i < total; i++) { #region 循环查询域名 GetVC: VerifyCode vc = GetVerifyCode(); if (vc != null) { InputVC: Invoke((MethodInvoker) delegate { FrmVC fvc = new FrmVC(vc.ImgByte); fvc.Owner = this; fvc.ShowDialog(); }); if (string.IsNullOrEmpty(VerifyCode)) { WriteTxt(txtProgress, domains[i] + ":没有输入验证码,重试。"); goto InputVC; } else if (VerifyCode == "stop") { WriteTxt(txtProgress, domains[i] + ":停止查询"); break; } else { if (ValidCode(VerifyCode, vc.Cookies)) { string icp = SearchExecute(domains[i], VerifyCode, vc.Cookies); if (string.IsNullOrEmpty(icp)) { fail++; WriteTxt(txtProgress, domains[i] + ":未备案。"); } else { success++; WriteTxt(txtResult, domains[i] + icp); } } else { WriteTxt(txtProgress, domains[i] + ":验证码校验失败,请重新输入。"); goto GetVC; } } } else { unknown++; WriteTxt(txtProgress, domains[i] + ":获取验证码失败"); goto GetVC; } #endregion BeginInvoke((MethodInvoker) delegate { lblProgress.Text = string.Format("{0} / {1} , 已备案:{2},未备案:{3},未知异常:{4}", i, total, success, fail, unknown); progressBar1.Value = i; }); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } BeginInvoke((MethodInvoker) delegate { btnQuery.Enabled = true; this.Text = "查询完成" + DateTime.Now.ToString(); }); }