关于r:RVest:从超市网页中提取类中的标签内容

RVest: extract tag content inside a class from a supermarket webpage

我正在尝试使用Rvest刮擦网络,但是我被卡住了,无法找到解决方案。
我设法成功地将页面加载到R中并提取了所需的HTML部分,但是我无法获取所需的数据。

我要抓取的一段HTML(不是真实的URL)是:

1
2
<img id="prod-image-53357" src="https://www.website.com.ar/media/98989898.jpg"
                           alt="insecticide 360 cc" />

我的代码:

1
2
3
4
5
6
library("rvest")
library("xml2")

url <-"https://www.website.com.ar/limpieza.html"
page <- read_html(url)
d <-page %>% html_nodes(" .open-modal")

如果我检查对象d,例如d [[4]],则会得到:

1
2
3
4
{html_node}

[1] <img id="prod-image-53357" src="https://www.website.com.ar/media/98989898.jpg
alt="insecticide 360 cc" />

我想提取href,alt和src作为文本并将其转换为数据框...

我尝试过:

1
d <-page %>% html_nodes(" .open-modal") %>% html_text()

1
d <-page %>% html_nodes(" .open-modal") %>% html_text('href')

没有成功...

有帮助吗?
在此先感谢!


可能您应该使用html_attr

1
2
3
4
5
library(rvest)
d <- page %>% html_nodes("a.open-modal")
data.frame(href = d %>% html_attr('href'),
           alt=d %>% html_attr('alt'),
           src = d %>% html_attr('src'))