【发布时间】:2021-05-10 12:16:50
【问题描述】:
我正在尝试使用 R 函数从网站收集多个值,我拥有的代码如下:
automatic = function(ETF) {
ETF = read_html(paste0('https://www.justetf.com/de-en/etf-profile.html?query=',ETF,'&groupField=index&from=search&isin=',ETF,'#overview'))
ETF = ETF %>%
general_info = ETF%>%html_nodes(".val") %>% html_text()
name_ETF = ETF%>%html_nodes(".h1") %>% html_text()
return(ETF)
}
如果我只是使用“.val”类,该函数可以工作,我可以使用 sapply 检索数据并将其保存到 data.frame,但是,如何在使用这两个类(.val 和 .h1 )?
提前谢谢你!
编辑:
这是我一直用来从 .val 获取信息的代码,但我现在想添加 .h1 类
automatic = function(ETF) {
ETF = read_html(paste0('https://www.justetf.com/de-en/etf-profile.html?query=',ETF,'&groupField=index&from=search&isin=',ETF,'#overview'))
ETF = ETF %>%
html_nodes(".val") %>% html_text()
return(ETF)
}
【问题讨论】:
标签: r web-scraping