我怎样才能下载HTML源代码在C# [英] How can I download HTML source in C#
本文介绍了我怎样才能下载HTML源代码在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能获得在C#中给出一个网址的HTML源代码?
How can I get the HTML source given a web address in c#?
推荐答案
您也可以下载使用的 WebClient类:
using System.Net;
//...
using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
client.DownloadFile("http://yoursite.com/page.html", @"C:\localfile.html");
// Or you can get the file content without saving it:
string htmlCode = client.DownloadString("http://yoursite.com/page.html");
//...
}
这篇关于我怎样才能下载HTML源代码在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文