C#获取远程网页中的所有链接URL(网络蜘蛛实现原理)

+展开
-C#
using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace HttpGet
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
System.Net.WebClient client = new WebClient();
byte[] page = client.DownloadData("http://news.163.com");
string content = System.Text.Encoding.UTF8.GetString(page);
string regex = "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']";
Regex re = new Regex(regex);
MatchCollection matches = re.Matches(content);

System.Collections.IEnumerator enu = matches.GetEnumerator();
while (enu.MoveNext() && enu.Current != null)
{
Match match = (Match)(enu.Current);
Console.Write(match.Value + "\r\n");
}
}
}
}



http://hi.baidu.com/isbx/blog/item/25317a8904a69eb00e244493.html

加支付宝好友偷能量挖...


评论(0)网络
阅读(102)喜欢(0)Asp.Net/C#/WCF