【问题标题】:How to get children element of html tag from SHDocVw如何从 SHDocVw 获取 html 标签的子元素
【发布时间】:2019-08-22 03:49:05
【问题描述】:

我有以下 Html 代码

<div class='blah'>...<div>
<div class='ct-bottom'>
  <button A>A</Button>
  <button B>B</Button>
</div>

我正在尝试使用 C# SHDocVw 来查找 div 元素并将子元素从中取出。这是C#代码

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.Navigate(Url_Home);

foreach (HTMLDivElementClass div in IE.Document.GetElementsByClassName("ct-bottom"))
{
    if (div.innerHTML !=null )
    {
        Console.WriteLine(div.children.length); // This does not work !
        break;
    }
}

错误信息:

'object' 不包含'length' 的定义,并且找不到接受'object' 类型的第一个参数的扩展方法'length'

【问题讨论】:

    标签: c# shdocvw


    【解决方案1】:

    想出了一个方法,但如果有其他方法可以分享,我们将不胜感激。

    foreach (HTMLDivElementClass div in IE.Document.GetElementsByClassName("ct-bottom"))
    {
      if (div.innerHTML != null)
      {
         Console.WriteLine((IHTMLElement)((IHTMLElementCollection)((IHTMLElement)div).children).length);
         break;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-24
      • 2012-02-06
      • 2020-02-01
      • 2021-12-26
      • 2020-02-18
      • 2013-05-13
      • 2012-05-16
      相关资源
      最近更新 更多