近日做了一下采集某个网页的内容,并获取其中所有的链接地址及链接标题。
其中用到了HttpWebRequest和正则表达式,代码备忘如下:
//WebClient wc = new WebClient();
//NetworkCredential nc = new NetworkCredential("用户名", "密码", "域名");
//wc.Credentials = nc;
//Response.Write(Server.HtmlEncode(wc.DownloadString("地址")));

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("地址");
req.Credentials = new NetworkCredential("用户名", "密码", "域名");
req.Method = "GET";
IAsyncResult ir = req.BeginGetResponse(null, null);
ir.AsyncWaitHandle.WaitOne();
}
这其中,正则表达式迷糊了我一会儿:因为没有使用惰性匹配,导致每一次都只能匹配到一条信息。。。。
相关文章:
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-11-22
-
2022-12-23
-
2021-10-19
-
2022-12-23