选择除列表和标题之外的所有内容

时间:2017-06-14 01:51:58

标签: html xpath html-agility-pack

我有一大堆HTML页面

<div class="ProductDescriptionContainer">
<p>This handsome Clergy Shirt has a trim low neckband with two reinforced buttonholes, one at the front, one at the back, to align with Ziegler's Collarettes, Collars and Collar buttons. This clerical shirt also includes convertible cuffs which may be buttoned or used with cuff links, and a single breast pocket on a plain button front.&nbsp;All of Ziegler's neckband shirts are designed to be worn with a Parsons Brand Collar or under one of our Cleric-Collar Shirtfronts. Order Now! Neck Sizes Available: 15-20.5" Including Half Sizes Sleeve Lengths Available: Short &nbsp;/&nbsp;Clergy Shirt Colors: &nbsp;Black, White, Grey, Church Purple, Medium Blue, French Blue, Navy</p>
<p style="text-align: left;"><strong>Clergy Shirt Details:&nbsp;</strong></p>
<ul>
<li>Neck Sizes Available: 15-20.5" Including Half Sizes</li>
<li>Colors Available: Black, White, Grey, Church Purple, Medium Blue, French Blue, Navy</li>
<li>Sleeve Lengths Available: Short</li>
<li>Collar: Black Dress Neckband</li>
<li>Made in the U.S.A</li>
<li>Collars and Buttons sold Separately*</li>
<li><a title="CLICK HERE FOR OUR SELECTION OF COLLARS AND COLLARETTES" href="http://www.zieglers.com/church-goods/apparel-and-vestments/collars-and-rabats/">CLICK HERE FOR OUR SELECTION OF COLLARS &amp; COLLARETTES</a></li>
</ul>
<p style="text-align: center;">*When buying a 2 ply collar or collarette for a neckband shirt it is best to order 1/2 size larger than the actual shirt you purchase for comfort.</p>
<p style="text-align: center;"><span style="color: #ff0000;"><strong>*Note- Church Purple, French Blue, Grey, Medium Blue, Navy and White are not standard colors. Availability and ship time will vary on these colors*</strong></span></p>
<p>&nbsp;</p>
</div>

我需要在HTML Agility包中选择除列表之外的所有html以及它正上方的标题。 我尝试使用follow-sibling和previous-sibling结合 not ,但是没有成功

1 个答案:

答案 0 :(得分:1)

你可以试试这样的LINQ:

var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(string);
var res = doc.DocumentNode.Descendants("p").Where(p => !p.ChildNodes.Any(c => c.Name.Equals("strong"));

这将选择不具有子strong元素的所有p元素。我知道这不是你想要的,但这会给你一个想法。您可以使用nextSibling并查找ul