C# 如何在WebBrowser控件C中查找特定单词#

C# 如何在WebBrowser控件C中查找特定单词#,c#,browser,mshtml,C#,Browser,Mshtml,我使用此代码在HTML中查找CDE。如何在具有不同id的标记页面中找到我的请求数据,例如,如果页面id为1我的结果为CDE,当页面id为2我的结果为IJK,我如何在搜索中设置id值 private void Form1_Load(object sender, EventArgs e) { webBrowser1.DocumentText = @"<html><head><title></title></head><body

我使用此代码在HTML中查找
CDE
。如何在具有不同id的标记页面中找到我的请求数据,例如,如果页面id为1我的结果为CDE,当页面id为2我的结果为IJK,我如何在搜索中设置id值

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>");
            }
        }
    }
}
private void Form1\u加载(对象发送方,事件参数e)
{
webBrowser1.DocumentText=@“”
+ ""
+@“ABCDEF”
+ ""
+@“GHIJKLMN”;
webBrowser1.DocumentCompleted+=HtmlEditorDocumentCompleted;
}
无效HtmlEditorDocumentCompleted(对象发送者,WebBrowserDocumentCompletedEventArgs e)
{
var document=(IHTMLDocument2)((WebBrowser)发送方).document.DomDocument;
如果(文档!=null)
{
IHTMLBodyElement bodyElement=作为IHTMLBodyElement的document.body;
if(bodyElement!=null)
{
IHTMLTxtRange trg=bodyElement.createTextRange();
如果(trg!=null)
{
训练动作(“角色”,2);
训练移动结束(“字符”,3);
trg.select();
trg.pasteHTML(“+trg.text+”);
}
}
}
}

我不知道,你需要做什么,你可能需要重新表述这个问题

但您可能需要查看
webBrowser1.Document.GetElementDyId()
以通过“id”获取特定元素