【问题标题】:Why html_nodes gives {xml_nodeset (0)}为什么 html_nodes 给出 {xml_nodeset (0)}
【发布时间】:2021-10-30 13:10:45
【问题描述】:

我正在尝试从 coinbase pro 获取硬币的名称。 html_nodes 返回 {xml_nodeset (0)}。知道如何解决这个问题吗?

网站:https://pro.coinbase.com/markets

selectorGagate.dOEGza

检查标签:xpath = '//[contains(concat( " ", @class, " " ), concat( " ", "dOEGza", " " ))]'*

url = "https://pro.coinbase.com/markets"
pg <- read_html(url)
html_nodes(pg, '.dOEGza')

{xml_nodeset (0)}

即使使用 xpath:

html_nodes(pg, xpath = '//*[contains(concat( " ", @class, " " ), concat( " ", "dOEGza", " " ))]')
{xml_nodeset (0)}

【问题讨论】:

    标签: css r screen-scraping rvest


    【解决方案1】:

    您没有从该网址获得任何结果,因为您在网页上看到的结果是从浏览器通过运行 JavaScript 动态发出的请求中提取的,该 JavaScript 会使用其他内容更新页面。 rvest 没有运行 JavaScript 的 JavaScript 引擎,因此您只能从初始 URI 中获取静态内容。

    对于可能提供动态内容的端点,与其在浏览器网络选项卡中搜索 API/XHR,不如在可用的情况下使用为服务提供的 API 更合适、更可靠。

    在这种情况下,看起来有用于该数据的免费公共 API

    查看此端点以 json 格式返回产品

    https://api.pro.coinbase.com/products
    

    来自文档:

    公共端点

    我们通过 IP 限制公共端点:每秒 10 个请求,最多 15 个 每秒的请求数。一些端点可能有自定义速率 限制。

    阅读更多:

    https://docs.pro.coinbase.com/#introduction

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2022-11-27
      • 2021-01-19
      • 1970-01-01
      • 2020-06-08
      • 2019-12-24
      相关资源
      最近更新 更多