c#国家行政规划

csharp

浏览数:962

2019-1-8

 private static List<City> NewMethod()
        {
            Task<string> task = GetHtml();
            string html = task.Result;
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='TRS_PreAppend']/p[@class='MsoNormal']");
            List<City> list = new List<City>();
            for (int i = 1; i < nodes.Count; i++)
            {
                City c = new City();
                HtmlNode node = nodes[i];
                string s = node.InnerText.ToString().Replace("&nbsp;", "").Trim();
                string[] ss = s.Split(' ');
                c.id = ss[0];
                c.name = ss[1];
                list.Add(c);
            }
            return list;
        }

        static async Task<string> GetHtml()
        {
            HttpClient hc = new HttpClient();
            return await hc.GetStringAsync("http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201703/t20170310_1471429.html");
        }