这是一个下载网页非常简单,但是非常有限的方法.
1 using System.Net; 2 3 var wc = new WebClient(); //新建一个WebClient对象 wc 4 string href = wz; //网址为字符串 wz 5 var html = wc.DownloadString(href); //html 就是wz的网页内容
得到这个html就可以做一些自己想做的事情.
此方法检索指定的资源。 下载该资源之后,此方法使用在 Encoding 属性中指定的编码将该资源转换为 String。
WebClient client = new WebClient (); // Optionally specify an encoding for uploading and downloading strings. client.Encoding = System.Text.Encoding.UTF8;
秉持用多少先学多少的原则,参见WebClient