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)));
        }
Beispiel #2
0
        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));
        }