C#Webページへのリンクの遍歴

4115 ワード


  
    
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://hi.baidu.com/jaysam/blog/item/bddb2bfa037b8f9359ee90e6.html? " );
string content = System.Text.Encoding.UTF8.GetString(page);
string regex = " src=[\\\"\\\'](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
" );
}
}
}
}