读书人

WebClinet 有关问题1

发布时间: 2012-10-10 13:58:11 作者: rapoo

WebClinet 问题1
WebClient wc = new WebClient();
string content = wc.DownloadString("http://pic.yesky.com/");
//Console.WriteLine(content);
string str = @"src=""(/.+/\w+.jpg)""";
MatchCollection matches = Regex.Matches(content, str);
foreach (Match match in matches)
{
if (match.Success)
{
// Console.WriteLine(match.Groups[1].Value);

string url = "http://pic.yesky.com" + match.Groups[1].Value;
//Console.WriteLine(url);
//Console.WriteLine(Path.GetFileName(url));
wc.DownloadFile(url, "img/"+Path.GetFileName(url));
}
}
Console.WriteLine("完成");
Console.Read();

为什么需要wc.DownloadFile(url, "img/"+Path.GetFileName(url)); 中的Path.GetFileName(url)步骤,不是直接放到img文件夹不就行了? 求大手详细解释一下,谢谢


[解决办法]
你没有看看那个URL是什么内容呀,能直接作为文件名吗?
Path.GetFileName(url)就是从url中获取文件名的。

读书人网 >C#

热点推荐