gpt4 book ai didi

c# - 获取 HttpElement 文本

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:45 25 4
gpt4 key购买 nike

<div id="div1">
<span>Span text 1</span>
<span>Span text 2</span>
Div Inner Text
</div>

如何只提取div1的文本(Div Inner Text)?

div1.innerText 返回和 span 的文本。

最佳答案

关于获取元素的内部文本也有类似的问题。

  • 解决方案 1:参见 this question

    HtmlElement e1 = webBrowser1.Document.GetElementById("elementId");
    string content = e1.InnerText
    MessageBox.Show(content);
  • 解决方案 2:使用 Javascript 和 HtmlDocument。 InvokeScript方法

    在您的 HTML 中:

    <script type="text/javascript">
    function getInnerText(id) {
    return document.getElementById(id)..innerText;
    }
    </script>

    C#

    Object[] objArray = new Object[1];
    objArray[0] = (Object)"elementId";
    string content = webBrowser1.Document.InvokeScript("getInnerText", objArray);
    MessageBox.Show(content);

关于c# - 获取 HttpElement 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4923381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com