志在指尖
用双手敲打未来

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

staticvoidMain(string[]args)
{
WebClientDemo();
Console.ReadLine();
}staticvoidWebClientDemo()
{
webContent=File.ReadAllText(“img2.txt”);varurlsList=webContent.Split(newstring[]{“\””,””},StringSplitOptions.None).ToList().Where(x=>x.StartsWith(“http”)).Where(x=>x.EndsWith(“jpg”)||x.EndsWith(“.png”)||x.EndsWith(“.jpeg”));foreach(varulinurlsList)C#
{
WebClientDownload(ul);
}
}staticvoidWebClientDownload(stringurl)
{try{using(WebClientwc=newWebClient())
{string[]urls=url.Split(newstring[]{“/”},StringSplitOptions.None);stringfileName=”Imgs2\\”+urls[urls.Length-1];
wc.DownloadFile(url,fileName);++num;
Console.WriteLine(url);
}
}catch{
}
}

未经允许不得转载:IT技术网站 » C# extract img url from web content then download the img
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载