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

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];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值