我尝试使用 HTML Agility Pack 从 html(-->xml) 文档(如下)中提取数据。div
包含“”的“ ”id=dealId_*****
是相关的。我想我知道如何继续,当我弄清楚如何div
用“ ”计算所有“ id=dealId_*****
”时。我尝试使用 XPath 方法“ starts-with
”,但它不起作用:
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>
PS:不幸的是,我只能使用 .NET 2.0。