Как я могу загрузить источник HTML в C#

У меня есть часть кода, которая работает для меня:

arr.sort((a, b) => a.name > b.name)

UPDATE: не работает всегда, поэтому это неверно: (

102
задан NotDan 1 March 2009 в 05:00
поделиться

2 ответа

Можно загрузить файлы класс 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");
}
178
ответ дан Hakan Fıstık 5 November 2019 в 11:29
поделиться

в основном:

using System.Net;
using System.Net.Http;  // in LINQPad, also add a reference to System.Net.Http.dll

WebRequest req = HttpWebRequest.Create("http://google.com");
req.Method = "GET";

string source;
using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()))
{
    source = reader.ReadToEnd();
}

Console.WriteLine(source);
39
ответ дан Colin 5 November 2019 в 11:29
поделиться
Другие вопросы по тегам:

Похожие вопросы: