Extract all divs containing specific keywords using XPath/HTML Agility Pack

lanceraccoon

New Member
I try to extract data from an html(-->xml)-document (below) using the HTML Agility Pack. The "\[code\]div\[/code\]"s that contain "\[code\]id=dealId_*****\[/code\]" are relevant. I think I know how to proceed, when I figure out how to just count all "\[code\]div\[/code\]"s with "\[code\]id=dealId_*****\[/code\]". I tried using the XPath-Method "\[code\]starts-with\[/code\]", but it didn't work:\[code\]HtmlDocument doc = new HtmlDocument();doc.LoadHtml(Sourcecode);int numberOfDIVs;numberOfDIVs = doc.DocumentNode.SelectNodes("//*[@id='jLocalDeals']/*[starts-with(@id, 'dealId_']").Count; <div id="jLocalDeals" class="dealsBlock" style=""> <h1> <div id="dealId_5474417" class="jDeal LEISURE_OFFERS"> <div id="dealId_5476688" class="jDeal SHOPPING"> <div id="dealId_5445019" class="jDeal TICKETS1 RESTAURANT1"> <div class="wrapper3Deals"></div> <div id="dealId_5474286" class="jDeal BEAUTY"> <div id="dealId_5476685" class="jDeal LEISURE_OFFERS"> <div id="dealId_5474466" class="jDeal SERVICES"> <div class="wrapper3Deals"></div> <div id="dealId_5466810" class="jDeal BEAUTY"> <div id="dealId_5425417" class="jDeal SERVICES"> <div id="dealId_5474329" class="jDeal SHOPPING"> <div class="wrapper3Deals"></div> <div id="dealId_5476703" class="jDeal SHOPPING"> <div id="dealId_5476729" class="jDeal SHOPPING"> <div id="dealId_5474702" class="jDeal HEALTHCARE"> <div class="wrapper3Deals"></div> <div id="dealId_5444044" class="jDeal TRAVEL1" style="display: block;"> <div id="dealId_5474444" class="jDeal LEISURE_OFFERS" style="display: block;"> <div id="dealId_5473774" class="jDeal TRAVEL1" style="display: block;"> <div class="wrapper3Deals"></div> </div> \[/code\]P.S.: Unfortunately I am only able to use .NET 2.0.
 
Back
Top