我正在尝试使用“rvest”从以下位置获取产品定价:。我正在使用下面的代码:
library(rvest)
library(tidyverse)
url <- "https://www.lowes.com/pl/Lawn-garden-hand-tools-Outdoor-tools-equipment-Outdoors/4294612737?goToProdList=true&int_cmp=LawnGardenHandTools:C:Outdoors:Merch:shop_all_copy"
html <- read_html(url)
price <- html %>%
html_node('body') %>%
xml_find_all("//span[contains(@class, 'h5 js-price v-spacing-mini art-pl-price')]") %>%
html_text() %>%
data.frame()
但是 - 这返回一个空数据框。
任何建议将不胜感激。
rvest
只能抓取静态 HTML 内容。
大多数现代商业网站都使用由 JavaScript 动态生成的动态 Web 内容。
为了抓取此类网站,您首先需要让网站生成您要查找的 HTML 内容,然后您就可以使用rvest
.
为此,您需要使用网络浏览器模拟器,例如硒 or Splash允许您在站点中移动并以编程方式查询数据。
RSelenium 需要安装Docker Selenium 服务器。这也推荐用于 Splash。
At the end of this long and interesting journey, you'll have to be creative so that the Website doesn't think that it's being queried by a robot :
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)