【问题标题】:Can't scrape a table with rvest不能用 rvest 刮桌子
【发布时间】:2021-05-08 02:15:55
【问题描述】:

我一直在尝试从这个页面上抓取一个表格:https://ficeda.com.mx/index.php?id=precios

我的代码是这样的

url_data <- "https://ficeda.com.mx/index.php?id=precios"

url_data %>% 
  read_html() %>% 
  html_node(xpath = "/html/body/div[1]/div/div/div[3]/table[1]") %>% 
  html_table()

但它给了我这个错误: UseMethod("html_table") 中的错误: 没有适用于“xml_missing”类对象的“html_table”方法

有人知道会发生什么吗?

谢谢!

【问题讨论】:

    标签: r web-scraping rvest


    【解决方案1】:

    该数据实际上位于 iframe 中。或者,发出您的初始请求并从 iframe 中提取 src 链接,然后在那里发出请求,或者直接向 iframe 文档发出请求:

    library(rvest)
    
    url_data <- "https://www.ficeda.com.mx/app_precios/pages/index/v2"
    
    url_data %>% 
      read_html() %>% 
      html_node('.category_title + table') %>% 
      html_table()
    

    来自原始端点的 iframe src:

    read_html('https://ficeda.com.mx/index.php?id=precios') %>% html_node('#linea2') %>% html_attr('src')
    

    【讨论】:

    • 非常感谢!这确实有效。
    猜你喜欢
    • 2019-07-22
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2018-12-07
    • 2020-04-14
    • 1970-01-01
    相关资源
    最近更新 更多