我有一组 html 页面。我想提取属性“border”= 1的所有表节点。这是一个例子:
<table border="1" cellspacing="0" cellpadding="5">
<tbody><tr><td>
<table border="0" cellpadding="2" cellspacing="0">
<tbody><tr>
<td bgcolor="#ff9999"><strong><font size="+1">CASEID</font></strong></td>
</tr></tbody>
</table>
<tr><td>[tbody]
</table>
在示例中,我想选择 border=1 的表节点,而不是 border = 0 的表。我使用的是
html_nodes()
来自 rvest
但无法弄清楚如何添加属性:html_nodes(x, "table")
最佳答案
查看 CSS3 selectors documentation这是从 html_nodes
的文档链接的.它提供了对 CSS 选择器语法的详尽解释。
对于你的情况,你想要
html_nodes(x, "tag[attribute]")
全选
tag
s 与 attribute
设置,或html_nodes(x, "tag[attribute=value]")
全选
tag
s 与 attribute
设置为 value
.
关于html - 如何使用 html_nodes 在 R 中选择 "attribute = x"的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59198803/