查找html标记并提取html文件中的文本

时间:2019-01-24 20:35:52

标签: html-agility-pack

我需要获取html的标题,并且它始终返回null对象。 html格式为:

 <tbody>
     <tr>
      <td>
      <table>
        <tr>
          <td>
            <div id="gateway-toolbar"
 class="getway-toobar">..</div> 
              <span class="catalog_name">Catalog</span>
              <h1 id="page-title">The Content I want</h1>
          </td>
        </tr>
      </table>
      </td>
      </tr>
    </tbody>

我的代码如下:

HtmlDocument html = new HtmlDocument();
html.LoadHtml(new WebClient().DownloadString(myURLLink));
var root = html.DocumentNode;

var titleNodes = root.SelectNodes("//h1[@id='page-title']");

但是titleNodes为空。请帮忙!

var titleNodes = root.SelectNodes(“ // * [@ id ='page-title']”);

我尝试了复制元素xpath,但仍然无法正常工作。

0 个答案:

没有答案