Http 敏捷包 - 访问兄弟姐妹?
使用 HTML Agility Pack 非常适合获取后代和整个表格等...但是在下面的情况下如何使用它你怎么能
...Html Code above...
<dl>
<dt>Location:</dt>
<dd>City, London</dd>
<dt style="padding-bottom:10px;">Distance:</dt>
<dd style="padding-bottom:10px;">0 miles</dd>
<dt>Date Issued:</dt>
<dd>26/10/2010</dd>
<dt>type:</dt>
<dd>cement</dd>
</dl>
...HTML Code below....
找到如果在这种情况下英里小于 15,我不明白你可以对元素做一些事情,但是您是否必须让所有元素找到正确的元素,然后找到数字只是为了检查其值?或者有没有办法将正则表达式与 Agility pack 一起使用以更好的方式实现这一目标......
Using the HTML Agility Pack is great for getting descendants and whole tables etc... but how can you use it in the below situation
...Html Code above...
<dl>
<dt>Location:</dt>
<dd>City, London</dd>
<dt style="padding-bottom:10px;">Distance:</dt>
<dd style="padding-bottom:10px;">0 miles</dd>
<dt>Date Issued:</dt>
<dd>26/10/2010</dd>
<dt>type:</dt>
<dd>cement</dd>
</dl>
...HTML Code below....
How could you find If miles was less than 15 in this case, I undestand you could do something with elements but would you have to get all elements find the correct one and then find the number just to check its value? Or is there are way to use regex with Agility pack to achieve this in a better way...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常确定(尚未检查)它支持
following-sibling::
轴,因此您可以任一找到节点"dt[. ='Distance:']"
然后找到node.SelectSingleNode("following-sibling::dd[1]")
- 或者(更简单)只使用node.NextSibling
如果您确定dd
始终紧跟在dt
后面。例如:
I'm pretty sure (haven't checked) that it supports the
following-sibling::
axis, so you could either find the node"dt[.='Distance:']"
and then findnode.SelectSingleNode("following-sibling::dd[1]")
- or (simpler) just usenode.NextSibling
if you are sure that thedd
always immediately follows thedt
.For example:
只获取 html 兄弟姐妹
Get just html siblings