日期:2014-05-17 浏览次数:21087 次
string url = "http://news.sina.com.cn/china/ ";//要获取的页面地址
WebRequest req = WebRequest.Create(url);
using (WebResponse res = req.GetResponse()) // GetResponse blocks until the response arrives
{
using (Stream ReceiveStream = res.GetResponseStream()) // Read the stream into a string
{
StreamReader sr = new StreamReader(ReceiveStream);
string resultstring = sr.ReadToEnd();
var list = Regex.Matches(resultstring, @"(?i)<a[^>]*?href=(['""]?)(?<Url>[^'""]*?/(\d+?)\.shtml)\1[^>]*?>(?<Text>[^<>]*?)</a>").OfType<Match>().Select(a=>a.Groups["Url"].Value).ToList();
/*
[0] "http://news.sina.com.cn/c/2013-06-26/150027504392.shtml" string