【发布时间】:2019-08-27 02:42:42
【问题描述】:
我正在尝试抓取不同的 URL 并将数据写入同一个 Excel 文件中,但每个 URL 都在一个页面中。
我的代码是这样的:
#install.packages("rvest")
library(XLConnect)
library(rvest)
{
for(i in c("2086","2167","2204")) {
url<-paste0("https://www.silversanz.com/producto/",i,)
}
dades<-read_html(url)
nom<-dades %>% html_nodes("h1.title") %>% html_text() %>% trimws()
preu<-dades %>% html_nodes("p.price--current") %>% html_text() %>% trimws()
info<-as.data.frame(cbind(nom,preu))
writeWorksheetToFile(file="C:/xxx.xxx.xlsx",
data=info,
sheet= "test",
clearSheets=TRUE
)
}
我有两个问题:
-
此代码不起作用 ->
for(i in c("2086","2167","2204")) { url<-paste0("https://www.silversanz.com/producto/",i,) 我不知道每个url怎么写一张
提前致谢:-)
【问题讨论】: