Html I';I’我正试图把网站上的数据收集到R
我不确定我的代码中缺少了什么。我正在尝试将数据从webscrape转换为R中的TIBLE。到目前为止,我的代码如下:Html I';I’我正试图把网站上的数据收集到R,html,r,web-scraping,Html,R,Web Scraping,我不确定我的代码中缺少了什么。我正在尝试将数据从webscrape转换为R中的TIBLE。到目前为止,我的代码如下: library(tidyverse) library(rvest) # url I want the data from. NFL_2010.url <- "https://www.espn.com/nfl/standings/_/season/2010" # Use webscraping to import the data from the url into R
library(tidyverse)
library(rvest)
# url I want the data from.
NFL_2010.url <- "https://www.espn.com/nfl/standings/_/season/2010"
# Use webscraping to import the data from the url into R
NFL_2010 <- NFL_2010.url %>%
read_html(NFL_2010) %>%
#There is more than 1 table, so I'm trying to use html_nodes
html_nodes("table") %>%
html_table () %>%
#convert data to a tibble
as_tibble()
库(tidyverse)
图书馆(rvest)
#我想要从中获取数据的url。
NFL_2010.url%
#有不止一个表,所以我尝试使用html_节点
html_节点(“表”)%%>%
html_表()%>%
#将数据转换为TIBLE文件
作为_tible()
我在这里遗漏了什么?此页面的Webscraping返回一个列表,其中所有表被分成4部分。所以你必须把这些片段连接在一起,然后转换成2个tible。例如:
library(tidyverse)
library(rvest)
NFL_2010.url <- "https://www.espn.com/nfl/standings/_/season/2010"
NFL_2010 <- NFL_2010.url %>%
read_html() %>%
html_nodes("table") %>%
html_table()
# American Football Conference
NFL_2010_AFC <- bind_cols(NFL_2010[[1]], NFL_2010[[2]]) %>%
as_tibble()
# National Football Conference
NFL_2010_NFC <- bind_cols(NFL_2010[[3]], NFL_2010[[4]]) %>%
as_tibble()
库(tidyverse)
图书馆(rvest)
NFL_2010.url%
html_节点(“表”)%%>%
html_表()
#美式足球会议
NFL_2010_AFC%
作为_tible()
#全国足球大会
NFL\U 2010\U NFC%
作为_tible()
在这之后,它仍然需要一些数据清理…此页面的Webscraping返回一个列表,其中所有表被分成4部分。所以你必须把这些片段连接在一起,然后转换成2个tible。例如:
library(tidyverse)
library(rvest)
NFL_2010.url <- "https://www.espn.com/nfl/standings/_/season/2010"
NFL_2010 <- NFL_2010.url %>%
read_html() %>%
html_nodes("table") %>%
html_table()
# American Football Conference
NFL_2010_AFC <- bind_cols(NFL_2010[[1]], NFL_2010[[2]]) %>%
as_tibble()
# National Football Conference
NFL_2010_NFC <- bind_cols(NFL_2010[[3]], NFL_2010[[4]]) %>%
as_tibble()
库(tidyverse)
图书馆(rvest)
NFL_2010.url%
html_节点(“表”)%%>%
html_表()
#美式足球会议
NFL_2010_AFC%
作为_tible()
#全国足球大会
NFL\U 2010\U NFC%
作为_tible()
在那之后,它仍然需要一些数据清理