0

我正在使用 HTMLAgilityPack 在某些节点的列表中获取文本。基本上我正在读出一个带有以下 HTML 的 HTML 页面:

<div class="video-overview yt-grid-fluid">
   <h3 class="video-title-container">
       <span class="yt-badge-std">
            WATCHED
        </span>
      <a href="/watch?v=S5FCdx7Dn0o&amp;list=FLArRQZAMoAgECBIOn08gNeA&amp;index=1" title="Bob Marley - Buffalo soldier" class="yt-uix-tile-link yt-uix-sessionlink" data-sessionlink="ei=c9tWUb3eJaOzhgG6kYHYAg&amp;feature=plpp_video">
        <span class="title video-title" dir="ltr">Bob Marley - Buffalo soldier</span>
      </a>
   </h3>

      <p class="video-details">
        <span class="video-owner">
             by <span class="yt-user-name " dir="ltr">Pgroenberg</span>
        </span>

          <span class="video-view-count">
            44,342,136 views
          </span>
      </p>
  </div>

我想得到文本“鲍勃马利 - 布法罗士兵”,它在里面<span class="title video-title" dir">

我似乎找不到正确的模式:

string expression = @"//span[@class='title video-title' and @dir='ltr']/text()";
HtmlNodeCollection hnc = htmlDoc.DocumentNode.SelectNodes(expression);

hnc 将为空,因为没有节点与表达式匹配。为什么我的表达不起作用?

4

0 回答 0