c# - C# 从 html 中获取值
问题描述
我有这个 html
<a class="video" style="display: block" href="some text">
<img class="pic" src="" alt="">
<div class="title">some text</div>
</a>
<a class="video" style="display: block" href="some text">
<img class="pic" src="" alt="">
<div class="title">some text</div>
</a>
它多次下降。如何从href
标题中获取值?
我试过这个,但我不知道如何得到<div class="title">
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a[@class='video']"))
{
Console.WriteLine("node:" + node.GetAttributeValue("href", null));
}
解决方案
看看这是否适合你。
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a[@class='video']"))
{
Console.WriteLine("href: " + node.GetAttributeValue("href", null));
Console.WriteLine("title: " + node.SelectSingleNode("./div[@class='title']").InnerText);
}
推荐阅读
- python - 如何在 Amazon EC2 Linux 实例上安装和使用 Python 3.8?
- python - 获取NameError:名称'bot_token'未定义py.test
- python - 从双向链表中间删除元素时得到错误结果
- ios - 我将如何快速组织在多个视图控制器中重用的代码?
- ios - 使用未解析的标识符“CoreMLDelegate” - TFLite
- spring - 配置自定义权限评估器时如何避免警告消息“不符合所有 BeanPostProcessors 处理的条件”消息
- c# - `return` 后面的 `(int)` 是什么意思
- android - Android Kotlin - 使用一对多实体关系时出错
- reactjs - 从单独的文件中导入状态
- javascript - 如何可视化更新和稍后回滚 JavaScript 更新事务