标签:资源 read ble 密钥 support extern date ram directory
开发环境 :Win10 > Visual Studio 2019 > .Net Core 2.1
运行环境:Linux > CentOS 7
演示Demo:使用.Net Core 开发一个网络爬虫工具,将指定网址的所有图片下载到本地
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c ‘echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo‘
sudo yum update sudo yum install libunwind libicu sudo yum install dotnet-sdk-2.1
5、安装完毕后我们可以通过“dotnet --version”命令来测试是否安装成功(结果如图安装成功)
1 using System; 2 using System.IO; 3 using System.Net; 4 using System.Text.RegularExpressions; 5 using System.Threading; 6 7 namespace WebSpider 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 var l_strSaveDir = "imgs"; 14 var l_strHostName = "http://tieba.baidu.com/"; 15 16 using (var l_webClient = new WebClient()) 17 { 18 l_webClient.BaseAddress = l_strHostName; 19 20 if (!Directory.Exists(l_strSaveDir)) 21 Directory.CreateDirectory(l_strSaveDir); 22 23 Console.WriteLine("正在加载网络资源..."); 24 25 new Thread(() => 26 { 27 var l_strHtml = l_webClient.DownloadString(l_strHostName + "f?kw=java"); 28 var l_strMtchImgPattern = "<img src=\"(\\S+)\""; 29 var l_mtchImgs = Regex.Matches(l_strHtml, l_strMtchImgPattern, RegexOptions.IgnoreCase); 30 31 var l_iImgCount = l_mtchImgs.Count; 32 Console.WriteLine("资源加载完毕,正在下载"); 33 for (int i = 0; i < l_iImgCount; i++) 34 { 35 var l_strImgUrl = l_mtchImgs[i].Groups[1].Value; 36 l_webClient.DownloadFile(l_strImgUrl, Path.Combine(l_strSaveDir,Guid.NewGuid()+"."+Path.GetExtension(l_strImgUrl))); 37 Console.WriteLine(string.Format("正在下载({0}/{1})", (i + 1).ToString(), l_iImgCount.ToString())); 38 } 39 Console.WriteLine(string.Format("图片已全部下载完毕,保存地址{0}",l_strSaveDir)); 40 41 }).Start(); 42 } 43 } 44 } 45 }
如何将.Net Core应用程序部署在Linux操作系统上运行
标签:资源 read ble 密钥 support extern date ram directory
原文地址:https://www.cnblogs.com/insipid/p/11385426.html