How to read an HTML string using C #

I know how to read a line in a txt file, but for some reason C # does not detect the end of the line in HTML files. This code basically opens the html file and tries to parse line by line in search of the specified line. Even when just trying to print the first line of text in an HTML file, it is not displayed.

using (StreamReader sr = new StreamReader("\\\\server\\myFile.html"))
        {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                if(line == ("<td><strong>String I wantstrong></td>"))
                {
                    Label1.Text = "Text Found";
                    break;
                }
            }
        }

I tried this using a simple text file and it works great, just not when trying to parse an HTML file.

Thank.

+3
source share
4 answers

The best way is to use the HTML Agility Pack

You can learn more about this in the previous question.

Search C # HTML Parser

+4
source

HTML-, , XHTML, HTML XML System.XML?

0

, , . - :

  • HTML
  • HTML

.

, :

, , ,

 if(line == ("<td><strong>String I wantstrong></td>"))
 {
    Label1.Text = "Text Found";
    break;
 }

EXACT. , </ </strong>, , , , HTML- ().

0
source

Source: https://habr.com/ru/post/1785327/


All Articles