C# extract img url from web content then download the img

妖狐艹你老母 2023-01-13 10:55 201阅读 0赞
  1. static void Main(string[] args)
  2. {
  3. WebClientDemo();
  4. Console.ReadLine();
  5. }
  6. static void WebClientDemo()
  7. {
  8. webContent = File.ReadAllText("img2.txt");
  9. var urlsList = webContent.Split(new string[] { "\"", "" }, StringSplitOptions.None).ToList().Where(x => x.StartsWith("http")).Where(x => x.EndsWith("jpg") || x.EndsWith(".png") || x.EndsWith(".jpeg"));
  10. foreach (var ul in urlsList)
  11. {
  12. WebClientDownload(ul);
  13. }
  14. }
  15. static void WebClientDownload(string url)
  16. {
  17. try
  18. {
  19. using (WebClient wc = new WebClient())
  20. {
  21. string[] urls = url.Split(new string[] { "/" }, StringSplitOptions.None);
  22. string fileName = "Imgs2\\"+ urls[urls.Length - 1];
  23. wc.DownloadFile(url, fileName);
  24. ++num;
  25. Console.WriteLine(url);
  26. }
  27. }
  28. catch
  29. {
  30. }
  31. }

发表评论

表情:
评论列表 (有 0 条评论,201人围观)

还没有评论,来说两句吧...

相关阅读

    相关 img.item()跟img[x,y]

    简述 首先,cv2.imread()读取的图片默认情况下为彩图(三管道图片) 所以,在定位到对应(x,y) ( x , y ) 像素点上的时候,得到的就是三维向量