Download HTML Page in C#

2019-04-29 04:58发布

I am writing an app in c#, Is there a way to download a HTML page by giving my program its URL only. Foe example my program will get the URL www.google.com and download the HTML page?

标签: c# html url
2条回答
淡お忘
3楼-- · 2019-04-29 05:50

Use the WebClient class.

This is extracted from a sample on the msdn doc page:

using System;
using System.Net;
using System.IO;

public static string Download (string uri)
{
    WebClient client = new WebClient ();

    Stream data = client.OpenRead (uri);
    StreamReader reader = new StreamReader (data);
    string s = reader.ReadToEnd ();
    data.Close ();
    reader.Close ();
    return s;
}
查看更多
登录 后发表回答