using system;
using system.collections.generic;
using system.text;
using system.net;
using system.io;
namespace thief
{
    class program
    {
        static void main(string[] args)
        {
            
            try {
                webclient mywebclient = new webclient();
mywebclient.credentials = credentialcache.defaultcredentials;//获取或设置用于对向internet资源的请求进行身份验证的网络凭据。
byte[] pagedata = mywebclient.downloaddata("http://www.163.com");//从指定网站下载数据
string pagehtml = encoding.default.getstring(pagedata); //如果获取网站页面采用的是gb2312,则使用这句
//string pagehtml = encoding.utf8.getstring(pagedata); //如果获取网站页面采用的是utf-8,则使用这句
console.writeline(pagehtml);//在控制台输入获取的内容
                using (streamwriter sw = new streamwriter("c://test//ouput.html"))//将获取的内容写入文本
                {
                    sw.write(pagehtml);
                }
                console.readline(); //让控制台暂停,否则一闪而过了               
            }
            catch(webexception webex) {
                console.writeline(webex.message.tostring());
            }
        }
    }
}
注:内容转自菩提树下的杨过的博客
新闻热点
疑难解答