这里有源代码和我的xpath
我正在尝试选择第3个值但是即使选择第一个值也无法正常工作
HtmlDocument hdMyDoc = new HtmlDocument();
hdMyDoc.LoadHtml(File.ReadAllText("html.txt"));
HtmlNode hdNodes = hdMyDoc.DocumentNode.SelectSingleNode
(string.Format("//div[@class='rating'][3]", "div", "class", "rating"));
然而,当我写[1]
时,它确实有用
源代码
<div class="anatablo">
<div class="helpful">
Bu inceleme sizce faydalı mı? <button class="yesbutton"
onclick=
"location.href='http://www.teknobiyotik.com/advancedreviews/helpfulness/post/reviewId/3403/actionName/Yes/';"
type="button"></button> <button class="nobutton" onclick=
"location.href='http://www.teknobiyotik.com/advancedreviews/helpfulness/post/reviewId/3403/actionName/No/';"
type="button"></button>
</div>
<div class="baslik">
Yorumlayan : Ufuk
</div>
<table class="alttablo">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td class="yildiz">
<table cellspacing="0" class=
"ratings-list">
<tbody>
<tr>
<td class="label" style=
"font-weight: bold">
Fiyat</td>
</tr>
<tr>
<td>
<div class="rating-box"
style=
"margin-bottom:3px;">
<div class="rating"
style=
"width: 33%;">
</div>
</div>
</td>
</tr>
<tr>
<td class="label" style=
"font-weight: bold">
Kullanım Kolaylığı</td>
</tr>
<tr>
<td>
<div class="rating-box"
style=
"margin-bottom:3px;">
<div class="rating"
style=
"width: 66%;">
</div>
</div>
</td>
</tr>
<tr>
<td class="label" style=
"font-weight: bold">
Kalite</td>
</tr>
<tr>
<td>
<div class="rating-box"
style=
"margin-bottom:3px;">
<div class="rating"
style=
"width: 99%;">
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
<td class="yorumalani">
<div class="yorumbaslik">
<strong>Kocaman birşey</strong> (
06.07.2013 )
</div>Bu fiyata akasa ürünü hem de
isteyebileceğinizden daha büyük bir
mouse alanı. Yere adeta yapışıyor.
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table width="100%">
<tbody>
<tr>
<td>
<div class="review-footer" style="display:block;">
<table style="width:100%;">
<tbody>
<tr>
<td class="socialshare">
<!-- AW_AdvancedReviews Socialshare block start -->
Bu incelemeyi paylaşın <a href=
"http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.teknobiyotik.com%2Freview%2Fproduct%2Fview%2Fid%2F3403%2F%3F___SID%3DU&t=Kocaman%20bir%C5%9Fey"
target="_blank"><img alt="Facebook"
height="16" src=
"http://www.teknobiyotik.com/skin/frontend/default/default/advancedreviews/images/link-facebook.gif"
title="Add to Facebook" width=
"16"></a>
<!-- AW_AdvancedReviews Socialshare block end -->
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<ul></ul>
答案 0 :(得分:1)
尝试
hdMyDoc.DocumentNode.SelectSingleNode("(//div[@class='rating'])[3]");
xpath中的(和)括号至关重要。