コード例 #1
0
        public static void start()
        {
            HttpClient httpClient = new HttpClient();

            httpClient
            .PostAsync("http://hd.huachuan.gov.cn/aspx/gkml_list.aspx", null)
            .ContinueWith((postTask) =>
            {
                HttpResponseMessage response = postTask.Result;
                string cookie = response.Headers.GetValues("Set-Cookie").FirstOrDefault().Split(';')[0].Split('=')[1];
                Debug.WriteLine("----->响应cookie<-----:" + cookie);
                response.Content.ReadAsStringAsync().ContinueWith((readTask) =>
                {
                    IHtmlDocument source = new JumonyParser().Parse(readTask.Result);
                    string viewState     = source.FindSingle("input[name=__VIEWSTATE]").Attribute("value").Value();
                    int totalPage        = int.Parse(source.FindLast("option").InnerText());
                    Debug.WriteLine("----->数据总页数<-----:" + totalPage);
                    for (int i = 1; i <= totalPage; i++)
                    {
                        getByPage(cookie, viewState, i);
                    }
                });
            });
        }