gpt4 book ai didi

html-agility-pack - HTMLAgilityPack 仅迭代所有文本节点

转载 作者:行者123 更新时间:2023-12-04 16:25:02 24 4
gpt4 key购买 nike

这是一个 HTML 片段,我想要的只是获取文本节点并对其进行迭代。请让我知道。谢谢。

<div>
<div>
Select your Age:
<select>
<option>0 to 10</option>
<option>20 and above</option>
</select>
</div>
<div>
Help/Hints:
<ul>
<li>This is required field.
<li>Make sure select the right age.
</ul>
<a href="#">Learn More</a>
</div>
</div>

结果:
  • 选择您的年龄:
  • 0 到 10
  • 20岁及以上
  • 帮助/提示:
  • 这是必填字段。
  • 确保选择正确的年龄。
  • 了解更多
  • 最佳答案

    像这样的东西:

        HtmlDocument doc = new HtmlDocument();
    doc.Load(yourHtmlFile);

    foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()[normalize-space(.) != '']"))
    {
    Console.WriteLine(node.InnerText.Trim());
    }

    将输出这个:
    Select your Age:
    0 to 10
    20 and above
    Help/Hints:
    This is required field.
    Make sure select the right age.
    Learn More

    关于html-agility-pack - HTMLAgilityPack 仅迭代所有文本节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6344771/

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