Home >Backend Development >C++ >How Can I Retrieve HTML Source Code from a Web Address Using C#?
Obtaining HTML Source in C#
Given a web address, how do you retrieve its HTML source in C#?
Answer
To acquire the HTML source of a web page in C#, utilize the WebClient class. It empowers you to download files and retrieve content as strings without needing to save them to your local system.
Here's an example demonstrating the process:
using System.Net; using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable { client.DownloadFile("http://yoursite.com/page.html", @"C:\localfile.html"); // Alternatively, to get the file content without saving: string htmlCode = client.DownloadString("http://yoursite.com/page.html"); }
The above is the detailed content of How Can I Retrieve HTML Source Code from a Web Address Using C#?. For more information, please follow other related articles on the PHP Chinese website!