日期:2014-05-17  浏览次数:20912 次

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中获取文件名的。