У меня есть список из 38 000+ URL-адресов. У каждого URL есть таблица, которую я хотел бы очистить. Например:
library(rvest)
library(magrittr)
library(plyr)
#Doing URLs one by one
url<-"http://www.acpafl.org/ParcelResults.asp?Parcel=00024-006-000"
##GET SALES DATA
pricesdata <- read_html(url) %>% html_nodes(xpath = "//table[4]") %>% html_table(fill=TRUE)
library(plyr)
df <- ldply(pricesdata, data.frame)
Я хотел бы обобщить это на все URL-адреса в Parcels_ID.txt.
#(1) Step one is to generate a list of urls that we want to scrape data from
parcels <- read.csv(file="Parcels_ID.txt", sep="\t", header=TRUE, stringsAsFactors=FALSE) #import the data
parcelIDs <- as.vector(parcels$PARCELID) #reformat the column as a vector containing parcel IDs as individual elements of the vector
parcels$url = paste("http://www.acpafl.org/ParcelResults.asp?Parcel=", parcelIDs, sep="") #paste the web address and the parcel ID together to get the link to the parcel on the website
Теперь, когда у меня это есть, я хотел бы написать цикл, который проходит по каждому URL-адресу и извлекает таблицу, а затем помещает результаты в список фреймов данных. Вот тут у меня возникли проблемы:
#(2) Step to is to write a for loop that will scrape the tables from the individual pages
compiled<-list()
for (i in seq_along(parcels$url)){
##GET SALES DATA
pricesdata <- read_html(parcels$url[i]) %>% html_nodes(xpath = "//table[4]") %>% html_table(fill=TRUE)
compiled[[i]] <- ldply(pricesdata, data.frame)
}
Этот код никогда не завершается. Я был бы признателен за любые орлиные глаза, которые могут обнаружить ошибки или проблемы, или за любые предложения относительно лучших практик для написания этого цикла for, который создает кадр данных из таблиц, извлеченных с веб-сайтов.
Спасибо