/// <summary> /// 获取详情页PostData /// </summary> /// <param name="Certi_No"></param> /// <param name="postdata"></param> /// <returns></returns> public static void GetDetailsPostData(string Certi_No, string postdata, ref ConcurrentQueue <string> postqueue) { String html = "start"; try { while (!html.Contains("ERAC National Certification Database")) { HttpInfo info = new HttpInfo(); info.RequestUrl = Url; info.PostData = postdata; info.KeepLive = true; html = HttpMethod.HttpWork(info); Thread.Sleep(1); } List <string> list = RegexMethod.GetMutResult(reg_arget, html, 1); String ViewState = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); String EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); if (list.Count > 0) { foreach (var item in list) { String detailpost = String.Format(Details_PostData, "__EVENTTARGET=" + item.Replace("'", "").Replace("$", "%24"), ViewState, EventValidation, Certi_No); postqueue.Enqueue(detailpost); } } } catch { } }
static void Main(string[] args) { int i = 1; //标准头 HttpItem item = new HttpItem(); item.URL = $"https://hz.meituan.com/meishi/pn{i}/"; item.Postdata = ""; item.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04"; item.Referer = ""; item.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; item.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; item.Cookie = ""; item.ProxyIp = ""; item.ProxyUserName = ""; item.ProxyPwd = ""; item.Method = "GET"; //自定义头 item.Header.Add("Accept-Encoding", "gzip, deflate"); String html = HttpMethod.HttpWork(item).Html; //Console.WriteLine(html); var poiId1 = ExtractMethod.GetResults(ExtractType.Regex, html, "\"poiId\":(\\d+),", new RegexPam { Group = 1 }); var poiId = RegexMethod.GetMutResult("\"poiId\":(\\d+),", html, 1); //Console.WriteLine(poiId1); Console.ReadLine(); }
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { String newpath = String.Empty; if (!Directory.Exists(path)) { Form4 form4 = new Form4("错误:没有保存请求配置"); form4.Text = "错误"; form4.ShowDialog(); return; } Form6 form6 = new Form6(); form6.Text = "读取配置"; form6.ShowDialog(); if (form6.DialogResult == DialogResult.Cancel) { return; } if (form6.DialogResult == DialogResult.No) { Form4 form4 = new Form4("错误:程序错误,请联系程序员"); form4.Text = "错误"; form4.ShowDialog(); return; } if (form6.DialogResult == DialogResult.OK) { newpath = form6.pathname; } using (StreamReader sr = new StreamReader(newpath)) { string str = sr.ReadToEnd(); var reglist = RegexMethod.GetMutResult(".*?----(.*)", str, 1); var newreglist = RegexMethod.GetMutResult("(.*?)----(.*)", str, 1); textEdit1.Text = reglist[reglist.Count - 9].Replace("\r", ""); string postdata = reglist[reglist.Count - 8]; postdata = postdata.Replace("\r\n", ""); richEditControl1.Text = postdata.Replace("\r", "");; textEdit2.Text = reglist[reglist.Count - 7].Replace("\r", "");; textEdit4.Text = reglist[reglist.Count - 6].Replace("\r", "");; textEdit3.Text = reglist[reglist.Count - 5].Replace("\r", "");; textEdit5.Text = reglist[reglist.Count - 4].Replace("\r", "");; textEdit6.Text = reglist[reglist.Count - 3].Replace("\r", "");; textEdit8.Text = reglist[reglist.Count - 2].Replace("\r", "");; richEditControl2.Text = reglist[reglist.Count - 1].Replace("\r", ""); if (reglist.Count > 9) { for (int i = 0; i < reglist.Count - 9; i++) { HeadDic.TryAdd(newreglist[i], reglist[i]); } } if (HeadDic.Count > 0) { AddItem(HeadDic); } } barStaticItem1.Caption = "当前状态:读取配置完毕"; }
/// <summary> /// 下载图片按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem12_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GC.Collect(); tabNavigationPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textEdit1.Text)) { Form4 form4 = new Form4("错误:请求地址不合法"); form4.Text = "错误"; form4.ShowDialog(); barStaticItem1.Caption = "当前状态:取消图片请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textEdit1.Text)) { Form5 form5 = new Form5("警告:未检测到常规格式的下载地址,是否继续"); form5.Text = "警告"; form5.ShowDialog(); if (form5.DialogResult == DialogResult.Cancel) { barStaticItem1.Caption = "当前状态:取消图片下载"; return; } } barStaticItem1.Caption = "下载图片:" + Path.GetFileName(textEdit1.Text); xtraTabPage1.Controls.Clear(); xtraTabPage2.Controls.Clear(); html = String.Empty; Jhtml = String.Empty; #region 请求头配置 info = CreateHttp(); #endregion try { Image img = HttpMethod.DownPic(info); if (img == null) { Form4 form4 = new Form4("失败:下载失败"); form4.Text = "失败"; form4.ShowDialog(); return; } PictureEdit pictureEdit = new PictureEdit(); pictureEdit.Dock = DockStyle.Fill; pictureEdit.Image = img; tabNavigationPage1.Controls.Add(pictureEdit); } catch (Exception ex) { Form4 form4 = new Form4("程序错误:请联系程序员!"); form4.Text = "错误"; form4.ShowDialog(); } barStaticItem1.Caption = "下载图片:" + Path.GetFileName(textEdit1.Text) + "完毕"; }
/// <summary> /// 获取cid /// </summary> /// <param name="postdata"></param> /// <returns></returns> private static string GetCid(string postdata, ref string newpostdata) { String cid = String.Empty; String html = "start"; try { HttpInfo info = new HttpInfo(); info.RequestUrl = Url; info.PostData = postdata; info.AllowAutoRedirect = true; info.KeepLive = true; while (!html.Contains("Search Result")) { html = HttpMethod.HttpWork(info); Thread.Sleep(1); } cid = RegexMethod.GetSingleResult(reg_cid, html, 1); String eventarget = "__EVENTTARGET=" + RegexMethod.GetSingleResult(reg_newenent, html, 1).Replace("$", "%24"); String eventargument = "__EVENTARGUMENT=" + RegexMethod.GetSingleResult(reg_newenent, html, 2).Replace("$", "%24"); String ViewState = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); String EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); newpostdata = String.Format(Details_PostData, eventarget, eventargument, ViewState, EventValidation); } catch { } return(cid); }
public static void Execute(IOptions snapshot, ResultsViewModel results, RegexMethod regexMethod, TesterMode testerMode) { try { results.Reset(); if (testerMode == TesterMode.Invoke) { if (regexMethod == RegexMethod.Match) { ExecuteMatch(snapshot, results); } else if (regexMethod == RegexMethod.Replace) { ExecuteReplace(snapshot, results); } else if (regexMethod == RegexMethod.Split) { ExecuteSplit(snapshot, results); } } else if (testerMode == TesterMode.CsCode) { ExecuteCsCode(snapshot, results, regexMethod); } else if (testerMode == TesterMode.VbCode) { ExecuteVbCode(snapshot, results, regexMethod); } } catch (Exception ex) { results.SetText(ex.ToString()); } }
/// <summary> /// 通过API接口获取IP /// </summary> /// <param name="proxyapi"></param> /// <returns></returns> public List <string> GetIp(String proxyapi) { List <string> iplist = new List <string>(); String ip = String.Empty; String Html = String.Empty; Html = HttpMethod.FastGetMethod(proxyapi); iplist = RegexMethod.GetMutResult("[0-9]+?.[0-9]+?.[0-9]+?.[0-9]+?:[0-9]+", Html); return(iplist); }
/// <summary> /// 下载文件按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GC.Collect(); #region 请求头配置 info = CreateHttp(); #endregion xtraTabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textEdit1.Text)) { Form4 form4 = new Form4("错误:请求地址不合法"); form4.Text = "错误"; form4.ShowDialog(); barStaticItem1.Caption = "当前状态:取消文件下载"; return; } if (!RegexMethod.CheckRegex(checkurl, textEdit1.Text)) { Form5 form5 = new Form5("警告:未检测到常规格式的下载地址,是否继续"); form5.Text = "警告"; form5.ShowDialog(); if (form5.DialogResult == DialogResult.Cancel) { barStaticItem1.Caption = "当前状态:取消文件下载"; return; } } SaveFileDialog sf = new SaveFileDialog(); var arr = textEdit1.Text.Split('/'); String filename = arr[arr.Length - 1]; String type = filename.Split('.')[1]; String name = filename.Split('.')[0]; String filter = String.Format("{0}(*.{0})|*.{0}|所有文件(*.*)|*.*", type, type, type); sf.Filter = filter;//可以保存的格式 sf.FileName = arr[arr.Length - 1]; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (HttpMethod.DownLoadFile_ABPath(info, sf.FileName)) { Form4 form4 = new Form4("成功:下载成功"); form4.Text = "成功"; form4.ShowDialog(); } else { Form4 form4 = new Form4("失败:下载失败"); form4.Text = "失败"; form4.ShowDialog(); } } barStaticItem1.Caption = "当前状态:完毕"; }
/// <summary> /// 获取详情页 /// </summary> /// <param name="Certi_No"></param> /// <returns></returns> public static Dictionary <string, string> ENEC_Details(string Certi_No) { Dictionary <string, string> dirs = new Dictionary <string, string>(); String html = "start"; try { HttpInfo info = new HttpInfo(); info.RequestUrl = Url; info.User_Agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"; info.PostData = String.Format(PostData, Certi_No); info.AllowAutoRedirect = true; info.KeepLive = true; info.CC = new System.Net.CookieContainer(); while (!html.Contains("Consultation of") && !html.Contains("licenced products")) { html = HttpMethod.HttpWork(info); Thread.Sleep(1); } //处理数据 var list = RegexMethod.GetMutResult(reg_all, html, 1); if (list.Count > 1) { var titlelist = RegexMethod.GetMutResult(reg_title, list[0], 1); var detaillist = RegexMethod.GetMutResult(reg_details, list[1], 1); if (titlelist.Count == detaillist.Count) { for (int i = 0; i < titlelist.Count; i++) { if (i == titlelist.Count - 1) { if (detaillist[i].Contains("a href")) { String moreall = RegexMethod.GetSingleResult(reg_moreurl, detaillist[i], 1); dirs.Add(titlelist[i], moreall); } else { dirs.Add(titlelist[i], detaillist[i]); } } else { dirs.Add(titlelist[i], detaillist[i]); } } } } } catch { } return(dirs); }
/// <summary> /// 图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button10_Click(object sender, EventArgs e) { GC.Collect(); tabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("请求地址不合法"); toolStripStatusLabel1.Text = "取消图片请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textBox1.Text)) { DialogResult result = MessageBox.Show("未检测到常规格式的下载地址,是否继续", "警告", MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.Cancel) { toolStripStatusLabel1.Text = "取消图片请求"; return; } } toolStripStatusLabel1.Text = "下载图片:" + Path.GetFileName(textBox1.Text); tabPage1.Controls.Clear(); tabPage4.Controls.Clear(); tabPage5.Controls.Clear(); html = String.Empty; JsHtml = String.Empty; #region 请求头配置 info = CreateHttp(); #endregion try { Image img = HttpMethod.DownPic(info); if (img == null) { MessageBox.Show("下载失败"); } PictureBox box = new PictureBox(); box.Dock = DockStyle.Fill; box.Image = img; tabPage1.Controls.Add(box); } catch (Exception ex) { MessageBox.Show(ex.Message); } toolStripStatusLabel1.Text = "下载图片:" + Path.GetFileName(textBox1.Text) + "完毕"; }
/// <summary> /// 正则抽取匹配结果 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (String.IsNullOrEmpty(html)) { Form4 form4 = new Form4("错误:网页源码为空"); form4.Text = "错误"; form4.ShowDialog(); return; } if (String.IsNullOrEmpty(textEdit9.Text)) { Form4 form4 = new Form4("错误:正则表达式为空"); form4.Text = "错误"; form4.ShowDialog(); return; } if (String.IsNullOrEmpty(textEdit10.Text)) { Form4 form4 = new Form4("提示:层数为空,将使用默认值0"); form4.Text = "提示"; form4.ShowDialog(); textEdit10.Text = "0"; } richEditControl6.Text = ""; int lay = Convert.ToInt32(textEdit10.Text); if (checkEdit11.Checked) { try { var list = RegexMethod.GetMutResult(textEdit9.Text, html, lay); richEditControl6.Text = String.Join("\n", list); } catch { richEditControl6.Text = "未找到匹配结果"; } } else { try { richEditControl6.Text = RegexMethod.GetSingleResult(textEdit9.Text, html, lay); } catch { richEditControl6.Text = "未找到匹配结果"; } } barStaticItem1.Caption = "当前状态:正则抽取完成"; }
/// <summary> /// 获取详情页 /// </summary> /// <param name="Certi_No"></param> public static Dictionary <string, string> ERAC_Details(String detailspost, String Certi_No) { Dictionary <string, string> dirs = new Dictionary <string, string>(); String html = String.Empty; try { HttpInfo info = new HttpInfo(); info.PostData = detailspost; info.AllowAutoRedirect = true; info.RequestUrl = Url; while (!html.Contains("ERAC National Certification Database - ")) { html = HttpMethod.HttpWork(info); Thread.Sleep(1); } //处理数据 dirs.Add("CertNo", Certi_No); dirs.Add("Renewal_of", RegexMethod.GetSingleResult(reg_conditions, html, 1)); dirs.Add("Description", RegexMethod.GetSingleResult(reg_des, html, 1)); dirs.Add("Brand", RegexMethod.GetSingleResult(reg_brand, html, 1)); dirs.Add("EquipmentClass", RegexMethod.GetSingleResult(reg_equi, html, 1)); dirs.Add("Standard", RegexMethod.GetSingleResult(reg_stand, html, 1)); dirs.Add("CertifiedDate", RegexMethod.GetSingleResult(reg_cerdate, html, 1)); dirs.Add("ExpiryDate", RegexMethod.GetSingleResult(reg_expidate, html, 1)); var modellist = RegexMethod.GetMutResult(reg_model, html, 1); String model = string.Empty; if (modellist.Count > 0) { foreach (var modelitem in modellist) { model = model + modelitem + ";"; } } dirs.Add("Model", model); var ratinglist = RegexMethod.GetMutResult(reg_rating, html, 1); String rating = string.Empty; if (ratinglist.Count > 0) { foreach (var ratingitem in ratinglist) { rating = rating + ratingitem + ";"; } } dirs.Add("Rating", rating); } catch { } return(dirs); }
/// <summary> /// 获取证书编号对应详情 /// </summary> /// <param name="Certi_No"></param> private Dictionary <String, String> CQC_Details(String Certi_No) { Dictionary <String, String> dirs = new Dictionary <string, string>(); HttpInfo info = new HttpInfo(); String html = "start"; String code = String.Empty; String cookie = Get_Cookie(CQC_Details_Url); try { while (!html.Contains(Certi_No) || html.Contains("验证码输入有误") || html.Contains("请输入验证码")) { code = WmCodeHelper.Get_Code(cookie); info.RequestUrl = CQC_Details_Url; info.PostData = String.Format(CQC_PostData, Certi_No, code); info.Cookie = new CookieString(cookie, true); //info.Ip = ""; html = HttpMethod.HttpWork(info); Thread.Sleep(1); } if (html.Contains(Certi_No)) { //数据处理 var ths = XpathMethod.GetMutResult(xpath_title, html, 1); var strs = XpathMethod.GetMutResult(xpath_certi, html, 1); string fjurl = XpathMethod.GetSingleResult(xpath_certi + "[14]", html, 0); fjurl = RegexMethod.GetSingleResult(reg_fjurl, fjurl, 1); for (int i = 1; i < strs.Count; i++) { if (i == strs.Count - 1 && !String.IsNullOrEmpty(fjurl)) { dirs.Add(ths[i], fjurl); } else { dirs.Add(ths[i], strs[i]); } } //CCCInfo cccinfo = new CCCInfo(); //cccinfo.CertiNo = XpathMethod.GetSingleResult(xpath_certino, html); //cccinfo.Applicant = XpathMethod.GetSingleResult(xpath_appli1, html) + "\r\n" + XpathMethod.GetSingleResult(xpath_appli2, html); } } catch { } return(dirs); }
public static String ToString(RegexMethod value) { switch (value) { case RegexMethod.Match: return(Text_Match); case RegexMethod.Replace: return(Text_Replace); case RegexMethod.Split: return(Text_Split); } return(String.Empty); }
private string GetMethodName(MethodFormRouteData methodFormRouteData) { var match = RegexMethod.Match(methodFormRouteData.Form); if (match.Success == false) { return(string.Empty); } var value = match.Groups["Method"].Value; if (string.IsNullOrEmpty(this.MethodTemplate)) { return(value); } return(string.Format(this.MethodTemplate, value)); }
/// <summary> /// 抽象类中默认实现 传入证书号文本的绝对路径 读取证书号加入到队列中 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parms">证书号文件绝对路径</param> /// <returns></returns> public virtual void GetTask(object[] parms) { String path = String.Empty; #region 文件和路径参数校验 if (parms == null || parms?.Length == 0) { throw new Exception("传入路径参数错误"); } else { path = parms[0] as String; if (String.IsNullOrEmpty(path)) { throw new Exception("证书号路径为空"); } else if (!File.Exists(path)) { throw new Exception($"{path}不存在"); } } #endregion try { using (StreamReader sr = new StreamReader(path)) { String cernums_str = sr.ReadToEnd(); var nums = RegexMethod.RegSplit(Base_CerNum_SplitReg, cernums_str); nums?.ToList().ForEach(num => { if (!String.IsNullOrEmpty(num)) { CerQueue.Enqueue(num); } }); Console.WriteLine("成功装载{0}条证书号", nums.Length); } } catch (Exception ex) { Console.WriteLine("读取证书号失败"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); throw; } }
/// <summary> /// 下载文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button11_Click(object sender, EventArgs e) { GC.Collect(); #region 请求头配置 info = CreateHttp(); #endregion tabPage1.Controls.Clear(); String checkurl = ".+\\..+"; if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("请求地址不合法"); toolStripStatusLabel1.Text = "取消下载请求"; return; } if (!RegexMethod.CheckRegex(checkurl, textBox1.Text)) { DialogResult result = MessageBox.Show("未检测到常规格式的下载地址,是否继续", "警告", MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.Cancel) { toolStripStatusLabel1.Text = "取消下载请求"; return; } } SaveFileDialog sf = new SaveFileDialog(); var arr = textBox1.Text.Split('/'); String filename = arr[arr.Length - 1]; String type = filename.Split('.')[1]; String name = filename.Split('.')[0]; String filter = String.Format("{0}(*.{0})|*.{0}|所有文件(*.*)|*.*", type, type, type); sf.Filter = filter;//可以保存的格式 sf.FileName = arr[arr.Length - 1]; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (HttpMethod.DownLoadFile_ABPath(info, sf.FileName)) { MessageBox.Show("下载成功"); } else { MessageBox.Show("下载失败"); } } toolStripStatusLabel1.Text = "完毕"; }
private void button6_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(html)) { MessageBox.Show("网页源码为空"); return; } if (String.IsNullOrEmpty(textBox13.Text)) { MessageBox.Show("正则表达式为空"); return; } if (String.IsNullOrEmpty(textBox14.Text)) { MessageBox.Show("层数为空,将使用默认值0"); textBox14.Text = "0"; } int lay = Convert.ToInt32(textBox14.Text); if (checkBox4.Checked) { try { var list = RegexMethod.GetMutResult(textBox13.Text, html, lay); richTextBox1.Text = String.Join("\n", list); } catch { richTextBox1.Text = "未找到匹配结果"; } } else { try { richTextBox1.Text = RegexMethod.GetSingleResult(textBox13.Text, html, lay); } catch { richTextBox1.Text = "未找到匹配结果"; } } }
/// <summary> /// 获取PostData /// </summary> /// <param name="Certi_No"></param> /// <returns></returns> private static string GetPostData(String Certi_No) { String postdata = String.Empty; String html = "start"; try { while (!html.Contains("Online Search")) { html = HttpMethod.FastGetMethod(Url); Thread.Sleep(1); } String ViewState = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); String EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D"); postdata = String.Format(PostData, ViewState, EventValidation, Certi_No); } catch { } return(postdata); }
public static Boolean TryParse(String text, out RegexMethod value) { if (String.Equals(text, Text_Match, StringComparison.InvariantCultureIgnoreCase)) { value = RegexMethod.Match; return(true); } if (String.Equals(text, Text_Replace, StringComparison.InvariantCultureIgnoreCase)) { value = RegexMethod.Replace; return(true); } if (String.Equals(text, Text_Split, StringComparison.InvariantCultureIgnoreCase)) { value = RegexMethod.Split; return(true); } value = default; return(false); }
/// <summary> /// 请求获取详细信息 /// </summary> /// <param name="Certi_No"></param> public static Dictionary <string, string> TUVnd_Details(String Certi_No) { Dictionary <string, string> dirs = new Dictionary <string, string>(); String html = "start"; try { HttpInfo info = new HttpInfo(); info.RequestUrl = String.Format(Url, Certi_No); while (!html.Contains(Certi_No)) { html = HttpMethod.HttpWork(info); Thread.Sleep(1); } //处理数据 var list = RegexMethod.GetMutResult(reg_all, html, 1); int i = 0; foreach (var item in list) { if (item.Contains("cert_details_th")) { String title = RegexMethod.GetSingleResult(reg_title, item, 1); String details = RegexMethod.GetSingleResult(reg_details, item, 1); if (title != " " && details != " ") { if (String.IsNullOrEmpty(title)) { i++; title = "Custom" + i; } dirs.Add(title, details); } } } } catch { } return(dirs); }
static void ExecuteVbCode(IOptions snapshot, ResultsViewModel results, RegexMethod regexMethod) { var template = new Generators.VbCodeTemplate(snapshot, regexMethod); results.SetText(template.TransformText()); }
/// <summary> /// 配置请求头 /// </summary> /// <returns></returns> public HttpInfo CreateHttp() { HttpInfo info = new HttpInfo(); #region 请求头配置 info = new HttpInfo(textEdit1.Text); if (!String.IsNullOrEmpty(richEditControl1.Text)) { var list = RegexMethod.GetMutResult("[\u4e00-\u9fa5]+?", richEditControl1.Text); String newpostdata = richEditControl1.Text; for (int i = 0; i < list.Count; i++) { newpostdata = newpostdata.Replace(list[i], HttpMethod.URLEncode(list[i])); } info.PostData = newpostdata; } info.UseSystemProxy = checkEdit7.Checked; //info.Host = textBox17.Text; info.IgnoreWebException = true; info.User_Agent = textEdit2.Text; info.Referer = textEdit4.Text; info.ContentType = textEdit3.Text; info.Accept = textEdit5.Text; info.AcceptEncoding = textEdit6.Text; info.CheckUrl = checkEdit4.Checked; info.Expect100Continue = checkEdit5.Checked; if (!String.IsNullOrEmpty(textEdit8.Text)) { info.Encoding = Encoding.GetEncoding(textEdit8.Text); } if (!String.IsNullOrEmpty(richEditControl2.Text)) { info.Cookie = new CookieString(richEditControl2.Text, true); } else { info.CC = new CookieContainer(); } info.AllowAutoRedirect = checkEdit1.Checked; info.KeepLive = checkEdit2.Checked; if (checkEdit3.Checked) { info.Header.Add("X-Requested-With", "XMLHttpRequest"); } foreach (var item in HeadDic) { if (item.Key == "Host") { info.Host = item.Value; continue; } if (item.Key == "ProtocolVersion") { if (item.Value == "1.0") { info.ProtocolVersion = ProtocolVersionEnum.V10; } else { info.ProtocolVersion = ProtocolVersionEnum.V11; } continue; } if (item.Key == "proxy") { var arr = item.Value.Split('|'); if (arr.Length > 0) { info.Ip = arr[0]; } if (arr.Length > 1) { info.Proxy_UserName = arr[1]; } if (arr.Length > 2) { info.Proxy_PassWord = arr[2]; } continue; } info.Header.Add(item.Key, item.Value); } #endregion return(info); }
private void simpleButton1_Click(object sender, EventArgs e) { //Form1 form1 = new Form1(); string key = string.Empty; if (!checkEdit1.Checked) { switch (comboBoxEdit1.SelectedIndex) { case 0: key = "Host"; break; case 1: key = "ProtocolVersion"; break; case 2: key = "proxy"; break; } if (comboBoxEdit1.SelectedIndex == 0) { if (String.IsNullOrEmpty(textEdit1.Text)) { Form4 form4 = new Form4("警告:请填写Host的Value值"); form4.Text = "警告"; form4.ShowDialog(); return; } if (Form1.HeadDic.TryAdd(key, textEdit1.Text)) { } else { Form4 form4 = new Form4("错误:Key已存在"); form4.Text = "错误"; form4.ShowDialog(); } } if (comboBoxEdit1.SelectedIndex == 1) { if (textEdit1.Text == "1.1") { if (Form1.HeadDic.TryAdd(key, "1.1")) { } else { Form4 form4 = new Form4("错误:Key已存在"); form4.Text = "错误"; form4.ShowDialog(); } } else { if (Form1.HeadDic.TryAdd(key, "1.0")) { } else { Form4 form4 = new Form4("错误:Key已存在"); form4.Text = "错误"; form4.ShowDialog(); } } } if (comboBoxEdit1.SelectedIndex == 2) { string str = RegexMethod.GetSingleResult("[0-9]+?.[0-9]+?.[0-9]+?.[0-9]+?:[0-9]+", textEdit1.Text); if (String.IsNullOrEmpty(textEdit1.Text) || String.IsNullOrEmpty(str)) { Form4 form4 = new Form4("警告:请按指定格式填写Proxy的Value值"); form4.Text = "警告"; form4.ShowDialog(); return; } if (Form1.HeadDic.TryAdd(key, textEdit1.Text)) { } else { Form4 form4 = new Form4("错误:Key已存在"); form4.Text = "错误"; form4.ShowDialog(); } } } else { if (String.IsNullOrEmpty(textEdit1.Text) || String.IsNullOrEmpty(textEdit2.Text)) { Form4 form4 = new Form4("警告:请填写自定义的key和Value值"); form4.Text = "警告"; form4.ShowDialog(); return; } if (Form1.HeadDic.TryAdd(textEdit2.Text, textEdit1.Text)) { } else { Form4 form4 = new Form4("错误:Key已存在"); form4.Text = "错误"; form4.ShowDialog(); } } key = null; this.Close(); }
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 }
// Returns null if nothing to do, Diagnostic if there's an error to report, or RegexType if the type was analyzed successfully. private static object?GetSemanticTargetForGeneration( GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken) { var methodSyntax = (MethodDeclarationSyntax)context.TargetNode; SemanticModel sm = context.SemanticModel; Compilation compilation = sm.Compilation; INamedTypeSymbol?regexSymbol = compilation.GetBestTypeByMetadataName(RegexName); INamedTypeSymbol?generatedRegexAttributeSymbol = compilation.GetBestTypeByMetadataName(GeneratedRegexAttributeName); if (regexSymbol is null || generatedRegexAttributeSymbol is null) { // Required types aren't available return(null); } TypeDeclarationSyntax?typeDec = methodSyntax.Parent as TypeDeclarationSyntax; if (typeDec is null) { return(null); } IMethodSymbol regexMethodSymbol = context.TargetSymbol as IMethodSymbol; if (regexMethodSymbol is null) { return(null); } ImmutableArray <AttributeData>?boundAttributes = regexMethodSymbol.GetAttributes(); if (boundAttributes is null || boundAttributes.Value.Length == 0) { return(null); } bool attributeFound = false; string?pattern = null; int? options = null; int? matchTimeout = null; string?cultureName = string.Empty; foreach (AttributeData attributeData in boundAttributes) { if (!SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, generatedRegexAttributeSymbol)) { continue; } if (attributeData.ConstructorArguments.Any(ca => ca.Kind == TypedConstantKind.Error)) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidGeneratedRegexAttribute, methodSyntax.GetLocation())); } if (pattern is not null) { return(Diagnostic.Create(DiagnosticDescriptors.MultipleGeneratedRegexAttributes, methodSyntax.GetLocation())); } ImmutableArray <TypedConstant> items = attributeData.ConstructorArguments; if (items.Length == 0 || items.Length > 4) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidGeneratedRegexAttribute, methodSyntax.GetLocation())); } attributeFound = true; pattern = items[0].Value as string; if (items.Length >= 2) { options = items[1].Value as int?; if (items.Length == 4) { matchTimeout = items[2].Value as int?; cultureName = items[3].Value as string; } // If there are 3 parameters, we need to check if the third argument is // int matchTimeoutMilliseconds, or string cultureName. else if (items.Length == 3) { if (items[2].Type.SpecialType == SpecialType.System_Int32) { matchTimeout = items[2].Value as int?; } else { cultureName = items[2].Value as string; } } } } if (!attributeFound) { return(null); } if (pattern is null || cultureName is null) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), "(null)")); } if (!regexMethodSymbol.IsPartialDefinition || regexMethodSymbol.IsAbstract || regexMethodSymbol.Parameters.Length != 0 || regexMethodSymbol.Arity != 0 || !SymbolEqualityComparer.Default.Equals(regexMethodSymbol.ReturnType, regexSymbol)) { return(Diagnostic.Create(DiagnosticDescriptors.RegexMethodMustHaveValidSignature, methodSyntax.GetLocation())); } RegexOptions regexOptions = options is not null ? (RegexOptions)options : RegexOptions.None; // If RegexOptions.IgnoreCase was specified or the inline ignore case option `(?i)` is present in the pattern, then we will (in priority order): // - If a culture name was passed in: // - If RegexOptions.CultureInvariant was also passed in, then we emit a diagnostic due to the explicit conflict. // - We try to initialize a culture using the passed in culture name to be used for case-sensitive comparisons. If // the culture name is invalid, we'll emit a diagnostic. // - Default to use Invariant Culture if no culture name was passed in. CultureInfo culture = CultureInfo.InvariantCulture; RegexOptions regexOptionsWithPatternOptions; try { regexOptionsWithPatternOptions = regexOptions | RegexParser.ParseOptionsInPattern(pattern, regexOptions); } catch (Exception e) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), e.Message)); } if ((regexOptionsWithPatternOptions & RegexOptions.IgnoreCase) != 0 && !string.IsNullOrEmpty(cultureName)) { if ((regexOptions & RegexOptions.CultureInvariant) != 0) { // User passed in both a culture name and set RegexOptions.CultureInvariant which causes an explicit conflict. return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), "cultureName")); } try { culture = CultureInfo.GetCultureInfo(cultureName); } catch (CultureNotFoundException) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), "cultureName")); } } // Validate the options const RegexOptions SupportedOptions = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ECMAScript | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.NonBacktracking | RegexOptions.RightToLeft | RegexOptions.Singleline; if ((regexOptions & ~SupportedOptions) != 0) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), "options")); } // Validate the timeout if (matchTimeout is 0 or < -1) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), "matchTimeout")); } // Parse the input pattern RegexTree regexTree; AnalysisResults analysis; try { regexTree = RegexParser.Parse(pattern, regexOptions | RegexOptions.Compiled, culture); // make sure Compiled is included to get all optimizations applied to it analysis = RegexTreeAnalyzer.Analyze(regexTree); } catch (Exception e) { return(Diagnostic.Create(DiagnosticDescriptors.InvalidRegexArguments, methodSyntax.GetLocation(), e.Message)); } // Determine the namespace the class is declared in, if any string?ns = regexMethodSymbol.ContainingType?.ContainingNamespace?.ToDisplayString( SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted)); var regexType = new RegexType( typeDec is RecordDeclarationSyntax rds ? $"{typeDec.Keyword.ValueText} {rds.ClassOrStructKeyword}" : typeDec.Keyword.ValueText, ns ?? string.Empty, $"{typeDec.Identifier}{typeDec.TypeParameterList}"); var regexMethod = new RegexMethod( regexType, methodSyntax, regexMethodSymbol.Name, methodSyntax.Modifiers.ToString(), pattern, regexOptions, matchTimeout, regexTree, analysis); RegexType current = regexType; var parent = typeDec.Parent as TypeDeclarationSyntax; while (parent is not null && IsAllowedKind(parent.Kind())) { current.Parent = new RegexType( parent is RecordDeclarationSyntax rds2 ? $"{parent.Keyword.ValueText} {rds2.ClassOrStructKeyword}" : parent.Keyword.ValueText, ns ?? string.Empty, $"{parent.Identifier}{parent.TypeParameterList}"); current = current.Parent; parent = parent.Parent as TypeDeclarationSyntax; } return(regexMethod);