C# extract img url from web content then download the img
程序员文章站
2022-06-11 16:28:32
static void Main(string[] args) { WebClientDemo(); Console.ReadLine(); } static void WebClientDemo() { webContent = File.ReadAllText("img2.txt"); var ... ......
static void main(string[] args) { webclientdemo(); console.readline(); } static void webclientdemo() { webcontent = file.readalltext("img2.txt"); 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")); foreach (var ul in urlslist) { webclientdownload(ul); } } static void webclientdownload(string url) { try { using (webclient wc = new webclient()) { string[] urls = url.split(new string[] { "/" }, stringsplitoptions.none); string filename = "imgs2\\"+ urls[urls.length - 1]; wc.downloadfile(url, filename); ++num; console.writeline(url); } } catch { } }
上一篇: Nginx服务器
下一篇: 使用yum安装nginx