html - 如何使用 html_nodes 在 R 中选择 "attribute = x"的节点?

标签 html r rvest

我有一组 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/

相关文章:

html - Express JS - 无法使用 Bootstrap 将 Pug 模板中的 DIV 中的文本居中

javascript - 如何在没有标签的情况下使用 fancybox 3?

r - 在 scale_x_discrete 中创建下标

html - 网页抓取:网页抓取的对象与网站上的信息不匹配并导致 RStudio 崩溃

r - 从维基百科表格中抓取网址

javascript - 将变量的内容附加到 html 内的文本文件

html - 具有居中文本和 float 元素的 Div

r - tidyverse 中所有可能的对

r - 用 R 填充长格式的不完整相关矩阵

html - 使用rvest或httr登录网页上的非标准表单