gpt4 book ai didi

c# - 使用 HtmlAgilityPack 解析 HTML 页面以按类选择 Divs

转载 作者:太空狗 更新时间:2023-10-29 15:39:26 24 4
gpt4 key购买 nike

我将 C# 与 HtmlAgilityPack 结合使用,我可以选择 ID 为 foo 的 div

var foos = from foo in htmlDoc.DocumentNode.Descendants("div")
where foo.Id == "foo"
select foo;

但是如何选择带有栏类的 div?

最佳答案

你可以像这样使用 XPATH

//div[@class='bar'] 

//*/div[@class='bar']

您也可以执行 && foo.Class == "bar"

关于c# - 使用 HtmlAgilityPack 解析 HTML 页面以按类选择 Divs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2656178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com