How can I get the HTML
code from a website, save it, and find some text by using a LINQ
expression?
I'm using the following code to get the source of a web page:
public static String code(string Url) { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url); myRequest.Method = "GET"; WebResponse myResponse = myRequest.GetResponse(); StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); string result = sr.ReadToEnd(); sr.Close(); myResponse.Close(); return result; }
How do I find the text within a div in the source of the web page?
Fire up Chrome and jump to the webpage you want to view the HTML source code. Right-click the page and click on “View Page Source,” or press Ctrl + U, to see the page's source in a new tab. A new tab opens along with all the HTML for the webpage, completely expanded and unformatted.
<div>: The Content Division element.
<code>: The Inline Code element The <code> HTML element displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code. By default, the content text is displayed using the user agent's default monospace font.
The text editors that come with an operating system (like Notepad) can be used to edit code. Since these are limited in functionality, users may wish to download a different text editor. Atom, Sublime, and NotePad++ are three popular text editors used today.
Better you can use the Webclient class to simplify your task:
using System.Net; using (WebClient client = new WebClient()) { string htmlCode = client.DownloadString("http://somesite.com/default.html"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With