public ActionResult Detail() { var data = Request.Form["data"]; var url = new Uri(data, UriKind.RelativeOrAbsolute); if (url.IsAbsoluteUri == false) { url = new Uri(new Uri("http://gsxt.gdgs.gov.cn/aiccips"), url); } var wc = new xWebClient(); wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:39.0) Gecko/20100101 Firefox/39.0"); if (Session["cookies"] != null) { wc.CookieContainer = Session["cookies"] as CookieContainer; } var htmlStr = wc.DownloadString(url); //var html=UTF8Encoding.UTF8.GetString(buffer); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(htmlStr); var list = new List <object>(); var trs = doc.DocumentNode.SelectNodes("//table[@class='detailsList' and position()=1]//tr"); foreach (var tr in trs) { int i = 1; while (true) { var th = tr.SelectSingleNode(string.Format("th[{0}]", i)); var td = tr.SelectSingleNode(string.Format("td[{0}]", i)); if (th == null || td == null) { break; } var o = new { name = th.InnerText, value = td.InnerText }; list.Add(o); i++; } //if (tr.ChildNodes.Count % 2 != 0) // continue; //for (int i = 0; i < tr.ChildNodes.Count / 2; i++) //{ // var o = new { name = tr.ChildNodes[i * 2].InnerText, value = tr.ChildNodes[i * 2 + 1].InnerText }; // list.Add(o); //} } return(Content(JsonConvert.SerializeObject(list))); }
public ActionResult Verify() { xWebClient wc = new xWebClient(); var rand = new Random(); var url = "http://gsxt.gdgs.gov.cn/aiccips//verify.html?random=" + rand.NextDouble(); var buffer = wc.DownloadData(url); Session["cookies"] = wc.CookieContainer; return(File(buffer, "image/png")); }
public ActionResult Detail() { var data = Request.Form["data"]; var url = new Uri(data, UriKind.RelativeOrAbsolute); if (url.IsAbsoluteUri == false) { url = new Uri(new Uri("http://gsxt.gdgs.gov.cn/aiccips"), url); } var wc = new xWebClient(); wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:39.0) Gecko/20100101 Firefox/39.0"); if (Session["cookies"] != null) wc.CookieContainer = Session["cookies"] as CookieContainer; var htmlStr = wc.DownloadString(url); //var html=UTF8Encoding.UTF8.GetString(buffer); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(htmlStr); var list = new List<object>(); var trs = doc.DocumentNode.SelectNodes("//table[@class='detailsList' and position()=1]//tr"); foreach (var tr in trs) { int i = 1; while(true) { var th = tr.SelectSingleNode(string.Format("th[{0}]", i)); var td = tr.SelectSingleNode(string.Format("td[{0}]", i)); if (th == null || td == null) break; var o = new { name = th.InnerText, value =td.InnerText }; list.Add(o); i++; } //if (tr.ChildNodes.Count % 2 != 0) // continue; //for (int i = 0; i < tr.ChildNodes.Count / 2; i++) //{ // var o = new { name = tr.ChildNodes[i * 2].InnerText, value = tr.ChildNodes[i * 2 + 1].InnerText }; // list.Add(o); //} } return Content(JsonConvert.SerializeObject(list)); }
public ActionResult Check() { var code = Request.Form["code"]; var text = Request.Form["text"]; var wc = new xWebClient(); if (Session["cookies"] != null) { wc.CookieContainer = Session["cookies"] as CookieContainer; } var values = new System.Collections.Specialized.NameValueCollection(); values.Add("code", code); values.Add("textfield", text); var str = wc.UploadValues("http://gsxt.gdgs.gov.cn/aiccips/CheckEntContext/checkCode.html", values); var json = JObject.Parse(str); if ((int)json["flag"] != 1) { return(Content("验证码错误")); } values.Clear(); values.Add("code", code); values.Add("textfield", (string)json["textfield"]); var htmlStr = wc.UploadValues("http://gsxt.gdgs.gov.cn/aiccips/CheckEntContext/showInfo.html", values); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(htmlStr); var nodes = doc.DocumentNode.SelectNodes("//div[@class='list']/ul"); var list = new List <object>(); foreach (var node in nodes) { var li1 = node.SelectSingleNode("li[1]/a"); var li2 = node.SelectSingleNode("li[2]"); var o = new { name = li1.InnerText, brief = li2.InnerText, data = li1.Attributes["href"].Value }; list.Add(o); } return(Content(JsonConvert.SerializeObject(list))); }
public ActionResult Check() { var code = Request.Form["code"]; var text = Request.Form["text"]; var wc = new xWebClient(); if (Session["cookies"] != null) wc.CookieContainer = Session["cookies"] as CookieContainer; var values = new System.Collections.Specialized.NameValueCollection(); values.Add("code", code); values.Add("textfield", text); var str = wc.UploadValues("http://gsxt.gdgs.gov.cn/aiccips/CheckEntContext/checkCode.html", values); var json = JObject.Parse(str); if ((int)json["flag"] != 1) return Content("验证码错误"); values.Clear(); values.Add("code", code); values.Add("textfield", (string)json["textfield"]); var htmlStr = wc.UploadValues("http://gsxt.gdgs.gov.cn/aiccips/CheckEntContext/showInfo.html", values); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(htmlStr); var nodes = doc.DocumentNode.SelectNodes("//div[@class='list']/ul"); var list = new List<object>(); foreach (var node in nodes) { var li1 = node.SelectSingleNode("li[1]/a"); var li2 = node.SelectSingleNode("li[2]"); var o = new { name = li1.InnerText, brief = li2.InnerText, data = li1.Attributes["href"].Value }; list.Add(o); } return Content(JsonConvert.SerializeObject(list)); }
public ActionResult Verify() { xWebClient wc = new xWebClient(); var rand = new Random(); var url = "http://gsxt.gdgs.gov.cn/aiccips//verify.html?random=" + rand.NextDouble(); var buffer = wc.DownloadData(url); Session["cookies"] = wc.CookieContainer; return File(buffer, "image/png"); }