使用 html 敏捷包获取课堂链接
有很多 tr 与类 alt。我想获取所有链接(或最后一个链接),但我无法弄清楚如何使用 html 敏捷包。
我尝试了 a 的变体,但我只得到所有链接或没有。它似乎不仅仅得到节点中的一个,这没有意义,因为我正在写 n.SelectNodes
html.LoadHtml(page);
var nS = html.DocumentNode.SelectNodes("//tr[@class='alt']");
foreach (var n in nS)
{
var aS = n.SelectNodes("a");
...
}
There are a bunch of tr's with the class alt. I want to get all the links (or the first of last) yet i cant figure out how with html agility pack.
I tried variants of a but i only get all the links or none. It doesnt seem to only get the one in the node which makes no sense since i am writing n.SelectNodes
html.LoadHtml(page);
var nS = html.DocumentNode.SelectNodes("//tr[@class='alt']");
foreach (var n in nS)
{
var aS = n.SelectNodes("a");
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 LINQ:
请注意,这也将匹配
;您可能想用正则表达式替换
Contains
调用。您还可以使用 Fizzler:
请注意,这两种方法也会返回非链接的锚点。
You can use LINQ:
Note that this will also match
<tr class="Malto">
; you may want to replace theContains
call with a regex.You could also use Fizzler:
Note that both methods will also return anchors that aren't links.
为什么不在单个查询中选择所有链接:
它对 html 有效:
Why not select all links in single query:
It's valid for html: