【问题标题】:HtmlAgilityPack how parse the *ngFor?HtmlAgilityPack如何解析*ngFor?
【发布时间】:2017-10-19 17:04:02
【问题描述】:

我有一个与 HtmlAgilityPack 相关的问题

这里是html代码

<div class="grid-container">
  <div class="grid-header">
    <div class="templateclass">
      <p-tabView [activeIndex]="activeTabIndex">
        <p-tabPanel *ngFor="let note of notes" [header]="note.noteName">
          <perfect-scrollbar class="ps-scroll">
            <div class="progressbarStyle">
              <p-progressBar [value]="note?.percentageCompleted"></p-progressBar>
            </div>
            <div [innerHTML]="note?.getDisplayHtml()">
            </div>
          </perfect-scrollbar>
        </p-tabPanel>
      </p-tabView>
    </div>
  </div>
</div>

这是我的 C# 代码

HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
string htmlData = File.ReadAllText(filePath);
htmlDocument.LoadHtml(htmlData);
IEnumerable<HtmlAgilityPack.HtmlNode> tagNodes = htmlDocument.DocumentNode.SelectNodes("//p-tabPanel");

为什么返回的 SelectNode 总是为 null?

我试图找到以下 p-tabView、p-tabPanel、完美滚动条、p-progressBar 和 div,我刚刚得到了完美滚动条和 div 的有价值的结果

你怎么看?

【问题讨论】:

    标签: c# html xpath html-agility-pack


    【解决方案1】:

    如果您只搜索小写字母,它会起作用:

    IEnumerable<HtmlAgilityPack.HtmlNode> tagNodes = htmlDocument.DocumentNode.SelectNodes("//p-tabpanel");
    

    你没有得到的节点都是大写的:p-tabView、p-tabPanel和p-progressBar。

    堆栈溢出参考:

    我在W3C XPath 1.0 specification 中没有找到任何官方参考资料。

    【讨论】:

    • 我从来没想过,它不区分大小写。谢谢!
    • 不客气。总是乐于提供帮助。然后,您可以验证答案是否解决了您的问题;)
    猜你喜欢
    • 1970-01-01
    • 2022-08-23
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 2012-02-15
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多