在R语言中找不到对象
我是一个使用R的新手,下面是我尝试使用循环a代码从多个页面中获取引用的尝试在R语言中找不到对象,r,web-scraping,R,Web Scraping,我是一个使用R的新手,下面是我尝试使用循环a代码从多个页面中获取引用的尝试 # Load Libraries library(rvest) # To Scrape library(tidyverse) # To Manipulate Data # Scrape Multiple Pages for (i in 1:4){ site_to_scrape <- read_html(paste0("http://quotes.toscrape.com/page/&qu
# Load Libraries
library(rvest) # To Scrape
library(tidyverse) # To Manipulate Data
# Scrape Multiple Pages
for (i in 1:4){
site_to_scrape <- read_html(paste0("http://quotes.toscrape.com/page/",i))
temp <- site_to_scrape html_nodes(".text") html_text()
content <- append(content, temp)
}
#Export Results To CSV File
write.csv(content, file = "content.csv", row.names = FALSE)
#加载库
图书馆(rvest)#刮
图书馆(tidyverse)#处理数据
#刮多页
(我在1:4中){
site_to_scrape我已经搜索并找到了在循环content=c()之前分配空对象的方法
#加载库
图书馆(rvest)#刮
图书馆(tidyverse)#处理数据
content=c()
#刮多页
(我在1:4中){
站点到站点刮取%
html_text()
content我已经搜索并找到了在循环content=c()之前分配空对象的方法
#加载库
图书馆(rvest)#刮
图书馆(tidyverse)#处理数据
content=c()
#刮多页
(我在1:4中){
站点到站点刮取%
html_text()
内容在循环中增长向量是非常低效的,如果你正在刮取许多页面。相反,你应该做的是初始化一个你事先知道的特定长度的列表
library(rvest)
n <- 4
content = vector('list', n)
# Scrape Multiple Pages
for (i in 1:n){
site_to_scrape <- read_html(paste0("http://quotes.toscrape.com/page/",i))
content[[i]] <- site_to_scrape %>%
html_nodes(".text") %>%
html_text()
}
write.csv(unlist(content), file = "content.csv", row.names = FALSE)
在循环中增长向量是非常低效的,如果你正在刮取许多页面,你应该做的是初始化一个列表,其中包含你事先知道的特定长度
library(rvest)
n <- 4
content = vector('list', n)
# Scrape Multiple Pages
for (i in 1:n){
site_to_scrape <- read_html(paste0("http://quotes.toscrape.com/page/",i))
content[[i]] <- site_to_scrape %>%
html_nodes(".text") %>%
html_text()
}
write.csv(unlist(content), file = "content.csv", row.names = FALSE)
all_urls <- paste0("http://quotes.toscrape.com/page/",1:4)
content <- unlist(lapply(all_urls, function(x)
x %>% read_html %>% html_nodes(".text") %>% html_text()))