Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中使用for循环到数据帧的Webscrape_R_Loops_Dataframe_Web Scraping - Fatal编程技术网

在R中使用for循环到数据帧的Webscrape

在R中使用for循环到数据帧的Webscrape,r,loops,dataframe,web-scraping,R,Loops,Dataframe,Web Scraping,我觉得我已经接近了这一点,但无法找到正确的解决方案。我想从多个页面中提取表格,并将结果保存到最后一个数据框中。所有表都将具有相同的结构。下面是我的代码和循环示例(实际上可能有1000页)。当我在一个页面上运行代码时,我可以得到结果,但我无法理解循环或如何将循环结果保存到数据帧中。看看我在下面做什么,谢谢你的帮助 library(textreadr) library(dplyr) library(rvest) for (event in (803:806)){ url<-paste0(

我觉得我已经接近了这一点,但无法找到正确的解决方案。我想从多个页面中提取表格,并将结果保存到最后一个数据框中。所有表都将具有相同的结构。下面是我的代码和循环示例(实际上可能有1000页)。当我在一个页面上运行代码时,我可以得到结果,但我无法理解循环或如何将循环结果保存到数据帧中。看看我在下面做什么,谢谢你的帮助

library(textreadr)
library(dplyr)
library(rvest)

for (event in (803:806)){
  url<-paste0('http://profightdb.com/cards/wwf/monday-night-raw-', event,'.html')
  webpage<-read_html(url)
  tbls_ls<-webpage %>%
    html_nodes('table') %>%
    .[[2]] %>%
    html_table(fill=TRUE)
}

库(textreadr)
图书馆(dplyr)
图书馆(rvest)
(803:806)中的事件{
url%
html_表(fill=TRUE)
}

也许可以将结果保存为数据帧列表

library(textreadr)
library(dplyr)
library(rvest)

tbls_ls <- vector(4, mode="list") # Initialize the list
i <- 1 # Initialize the index

for (event in (803:806)){
  url <- paste0('http://profightdb.com/cards/wwf/monday-night-raw-', event,'.html')
  webpage <- read_html(url)

  tbls_ls[[i]] <- webpage %>%
    html_nodes('table') %>%
    .[[2]] %>%
    html_table(fill=TRUE)

  i <- i+1  # Update the index
}    
库(textreadr)
图书馆(dplyr)
图书馆(rvest)

tbls_ls可能将结果保存为数据帧列表

library(textreadr)
library(dplyr)
library(rvest)

tbls_ls <- vector(4, mode="list") # Initialize the list
i <- 1 # Initialize the index

for (event in (803:806)){
  url <- paste0('http://profightdb.com/cards/wwf/monday-night-raw-', event,'.html')
  webpage <- read_html(url)

  tbls_ls[[i]] <- webpage %>%
    html_nodes('table') %>%
    .[[2]] %>%
    html_table(fill=TRUE)

  i <- i+1  # Update the index
}    
库(textreadr)
图书馆(dplyr)
图书馆(rvest)
待定