从C#中的打开窗口获取网页源

时间:2014-01-30 09:49:18

标签: c# html window webpage

我希望从c#获取任何chrome,firefox,ie等窗口的网页源代码 我该怎么用?

我的应用:

1 个答案:

答案 0 :(得分:0)

您应该使用以下代码:

using System.Net;
//...
using (WebClient webClient = new WebClient ())
{
    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代码中,您将获得预期的html源代码并将其显示在文本查看器中。