获取网站某页面的html信息两种方法

来源:互联网 发布:恒大淘宝足球股价 编辑:程序博客网 时间:2024/05/21 20:46
        WebClient wc = new WebClient();        string str = wc.DownloadString("http:/xxxxxx/regedit/login_check.asp");        String str1 = "正则表达式";        MatchCollection mc = Regex.Matches(str, str1);        //循环获取数据,操作          for (int i = 0; i < mc.Count; i++)        {            Match m = mc[i];        }



ASCIIEncoding encoding = new ASCIIEncoding();            //参数            byte[] data = encoding.GetBytes("username=ddd&password=123456");            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxxx/regedit/login.asp");            request.Method = "Post";            request.ContentType = "application/x-www-form-urlencoded";            request.ContentLength = data.Length;            request.KeepAlive = true;            //发送数据            Stream newStream = request.GetRequestStream();            newStream.Write(data, 0, data.Length);            newStream.Close();            //以下俩句不可缺少            HttpWebResponse response = (HttpWebResponse)request.GetResponse();            //(int)response.StatusCode 返回请求结果状态码            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);            string content = reader.ReadToEnd();            String str1 = "正则表达式";            MatchCollection mc = Regex.Matches(content, str1);            //循环获取数据,操作              for (int i = 0; i < mc.Count; i++)            {                Match m = mc[i];            }



原创粉丝点击