r - 不能用 rvest 刮桌子
问题描述
我一直试图从这个页面刮一张桌子: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”):没有适用于“html_table”的方法应用于“xml_missing”类的对象
有谁知道可能会发生什么?
谢谢!
解决方案
该数据实际上位于 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')
推荐阅读
- django - DRF 中的 KeyError“请求”
- sql-server - 从 .bak 文件中恢复数据
- java - 我在哪里可以找到 Java 8u241?
- html - 通过导航栏创建类
- pyqt5 - CheckBox 到一个变量。PyQt5
- python - 如何在不使用 python 循环的情况下检测和转换列值的单位?
- angular - 如何使用数组在角度 7 中的 for 循环中填充 Flex 布局的内容
- r - 如何在 dplyr 分组数据上使用 rollmean
- c++ - 我的代码已成功提交,但尝试在代码厨师上运行代码时出现 SIGSEGV 错误
- css - 我尝试在 macOS 上的 CSS 中回退 SF Compact Rounded,而不是 -applye-system