Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the text within a div in the source of a web page using C#

Tags:

html

c#

linq

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?

like image 982
ggcodes Avatar asked May 20 '13 03:05

ggcodes


People also ask

How you would locate the HTML code of an element in a 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.

What does Div stand for in HTML?

<div>: The Content Division element.

Which element denotes that the text is a short fragment of computer code?

<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.

Which of the following is a text editor in HTML?

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.


1 Answers

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"); } 
like image 144
Santosh Panda Avatar answered Oct 06 '22 18:10

Santosh Panda