好的,这里的源代码和我的xpath
我正在尝试选择第三个值,但是即使选择第一个值也无法正常工作
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>
参考方案
试试看
hdMyDoc.DocumentNode.SelectSingleNode("(//div[@class='rating'])[3]");
xpath中的(和)括号至关重要。
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…
从C#调用javascript函数不起作用 - c#大家好,我在popupscrit.js文件中使用以下方法:function afficherMessageInfo( id, message) { //Get the A tag alert('executing the client code'); //Get the screen height and width var maskHe…
在PHP文件中调用javascript函数并在加载HTML文件之后? - javascript我需要在我的php中调用js函数,但无法正常工作。有人可以告诉我我在做什么错吗?我该如何轻松地做到这一点?谢谢!我有三个文件: mail.php负责发送$ _POST的内容(工作正常)。我调用我的javascript函数来切换模式,具体取决于邮件是否已发送。 <? ... $response = $sendgrid->send($email);…
将python scikit学习模型导出到pmml - python我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…