久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

        <bdo id='atRmb'></bdo><ul id='atRmb'></ul>
      <tfoot id='atRmb'></tfoot>

    1. <small id='atRmb'></small><noframes id='atRmb'>

      <legend id='atRmb'><style id='atRmb'><dir id='atRmb'><q id='atRmb'></q></dir></style></legend>
      <i id='atRmb'><tr id='atRmb'><dt id='atRmb'><q id='atRmb'><span id='atRmb'><b id='atRmb'><form id='atRmb'><ins id='atRmb'></ins><ul id='atRmb'></ul><sub id='atRmb'></sub></form><legend id='atRmb'></legend><bdo id='atRmb'><pre id='atRmb'><center id='atRmb'></center></pre></bdo></b><th id='atRmb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='atRmb'><tfoot id='atRmb'></tfoot><dl id='atRmb'><fieldset id='atRmb'></fieldset></dl></div>

        使用 HTMLAgilityPack 僅提取頁面文本

        extracting just page text using HTMLAgilityPack(使用 HTMLAgilityPack 僅提取頁面文本)
        <tfoot id='00oAW'></tfoot>

        1. <legend id='00oAW'><style id='00oAW'><dir id='00oAW'><q id='00oAW'></q></dir></style></legend>
          • <bdo id='00oAW'></bdo><ul id='00oAW'></ul>

                  <tbody id='00oAW'></tbody>
                <i id='00oAW'><tr id='00oAW'><dt id='00oAW'><q id='00oAW'><span id='00oAW'><b id='00oAW'><form id='00oAW'><ins id='00oAW'></ins><ul id='00oAW'></ul><sub id='00oAW'></sub></form><legend id='00oAW'></legend><bdo id='00oAW'><pre id='00oAW'><center id='00oAW'></center></pre></bdo></b><th id='00oAW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='00oAW'><tfoot id='00oAW'></tfoot><dl id='00oAW'><fieldset id='00oAW'></fieldset></dl></div>

                  <small id='00oAW'></small><noframes id='00oAW'>

                  本文介紹了使用 HTMLAgilityPack 僅提取頁面文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  好的,所以我對 HTMLAgilityPack 中使用的 XPath 查詢真的很陌生.

                  Ok so i am really new to XPath queries used in HTMLAgilityPack.

                  讓我們考慮這個頁面 http://health.yahoo.net/articles/healthcare/what-your-favorite-flavor-says-about-you.我想要的是只提取頁面內容而不是其他內容.

                  So lets consider this page http://health.yahoo.net/articles/healthcare/what-your-favorite-flavor-says-about-you. What i want is to extract just the page content and nothing else.

                  為此,我首先刪除腳本和樣式標簽.

                  So for that i first remove script and style tags.

                  Document = new HtmlDocument();
                          Document.LoadHtml(page);
                          TempString = new StringBuilder();
                          foreach (HtmlNode style in Document.DocumentNode.Descendants("style").ToArray())
                          {
                              style.Remove();
                          }
                          foreach (HtmlNode script in Document.DocumentNode.Descendants("script").ToArray())
                          {
                              script.Remove();
                          }
                  

                  之后我嘗試使用//text() 來獲取所有文本節點.

                  After that i am trying to use //text() to get all the text nodes.

                  foreach (HtmlTextNode node in Document.DocumentNode.SelectNodes("http://text()"))
                          {
                              TempString.AppendLine(node.InnerText);
                          }
                  

                  但是,我不僅得到了文本,而且還得到了許多/r/n 字符.

                  However not only i am not getting just text i am also getting numerous /r /n characters.

                  在這方面我需要一些指導.

                  Please i require a little guidance in this regard.

                  推薦答案

                  如果你認為 scriptstyle 節點只有孩子的文本節點,你可以使用這個XPath 表達式獲取不在 scriptstyle 標記中的文本節點,這樣您就無需事先刪除節點:

                  If you consider that script and style nodes only have text nodes for children, you can use this XPath expression to get text nodes that are not in script or style tags, so that you don't need to remove the nodes beforehand:

                  //*[not(self::script or self::style)]/text()
                  

                  您可以使用 XPath 的 normalize-space() 進一步排除純空格的文本節點:

                  You can further exclude text nodes that are only whitespace using XPath's normalize-space():

                  //*[not(self::script or self::style)]/text()[not(normalize-space(.)="")]
                  

                  或更短的

                  //*[not(self::script or self::style)]/text()[normalize-space()]
                  

                  但您仍然會得到可能有前導或尾隨空格的文本節點.這可以按照@aL3891 的建議在您的應用程序中處理.

                  But you will still get text nodes that may have leading or trailing whitespace. This can be handled in your application as @aL3891 suggests.

                  這篇關于使用 HTMLAgilityPack 僅提取頁面文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)

                1. <legend id='40l5D'><style id='40l5D'><dir id='40l5D'><q id='40l5D'></q></dir></style></legend>
                          <bdo id='40l5D'></bdo><ul id='40l5D'></ul>
                          <i id='40l5D'><tr id='40l5D'><dt id='40l5D'><q id='40l5D'><span id='40l5D'><b id='40l5D'><form id='40l5D'><ins id='40l5D'></ins><ul id='40l5D'></ul><sub id='40l5D'></sub></form><legend id='40l5D'></legend><bdo id='40l5D'><pre id='40l5D'><center id='40l5D'></center></pre></bdo></b><th id='40l5D'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='40l5D'><tfoot id='40l5D'></tfoot><dl id='40l5D'><fieldset id='40l5D'></fieldset></dl></div>

                          <small id='40l5D'></small><noframes id='40l5D'>

                          <tfoot id='40l5D'></tfoot>

                            <tbody id='40l5D'></tbody>

                            主站蜘蛛池模板: 最新中文字幕在线观看 | 国内福利视频 | 久久久久久网 | 国产视频成人 | 欧美视频一区二区 | 特级特黄aaaa免费看 | 欧美黄色片 | 日韩激情网站 | 免费观看一级毛片 | 欧美一级在线播放 | 欧美一区二 | 亚洲无av在线中文字幕 | 一区二区视频在线播放 | 日韩一级在线 | 欧美精品网站 | 欧美国产日韩一区二区 | 国产不卡在线 | 国产无遮挡又黄又爽免费网站 | 啪啪综合网| 欧美精品99久久久 | 国产午夜精品视频 | 精品国产一二三区 | 成人免费在线播放 | 日韩网站在线观看 | 欧美日韩免费在线 | 久热精品视频 | 日韩一区二区在线播放 | 国产欧美日韩综合 | 国产黄色片视频 | 99re在线观看视频 | 欧美日韩国产一区二区 | 国产一区二区日韩 | 黄色免费毛片 | 日韩精品在线视频 | 国产在线观看一区 | 欧美黄视频 | 亚洲在线视频 | 日韩一级在线观看 | 黑人精品xxx一区一二区 | 最新国产精品 | 日韩欧美一区二区三区久久婷婷 |