How to find a specific word in a C # WebBrowser control

I use this code to find CDEin HTML. How can I find my request data on a tag page with different identifiers, for example, if page ID is 1 , my result is CDE and when page ID 2 is my IJK result . How to set id value in my search?

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.DocumentText = @"<html><head><title></title></head><body>" 
                               + "<page id=\"1\">"
                               + @"ABCDEF</page>"
                               + "<page id=\"2\">"
                               + @"GHIJKLMN</page></body></html>";

    webBrowser1.DocumentCompleted += HtmlEditorDocumentCompleted;
}

void HtmlEditorDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    var document = (IHTMLDocument2)((WebBrowser)sender).Document.DomDocument;

    if (document != null)
    {
        IHTMLBodyElement bodyElement = document.body as IHTMLBodyElement;

        if (bodyElement != null)
        {
            IHTMLTxtRange trg = bodyElement.createTextRange();

            if (trg != null)
            {
                trg.move("character", 2);
                trg.moveEnd("character", 3);
                trg.select();
                trg.pasteHTML("<font color=#FF0000><strike>" + trg.text + "</strike></font>");
            }
        }
    }
}
+3
source share
1 answer

I have no idea what you need to do, you may have to rephrase the question ...

But you might want to take a look at webBrowser1.Document.GetElementDyId()to get a specific item using "id"

+1
source

All Articles