用 R 抓取,只有第一个实例在列表中被抓取
Scraping with R, only first instance being scraped in the list
我已经抓取了一些网站,但我的输出并没有真正的问题,但我不明白为什么在这个特定的网站上我只得到了我试图抓取的第一个实例,而不是所有的36.
我正在尝试收集页面上所有玩家的 href
链接并将它们保存到列表或数据框中。
我当前的代码是:
library(XML)
library(rvest)
match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
WSm <- read_html(match)
Players <- WSm %>% html_node(".player-name") %>% html_attr("href") %>% as.character()
这给了我:
[1] "/fotballdata/person/profil/?fiksId=2820074"
并非我所期望的所有玩家的所有 href
的完整列表。有人能帮忙吗?
使用 html_nodes() 而不是 html_node()
library(XML)
library(rvest)
match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
WSm <- read_html(match)
Players <- WSm %>% html_nodes(".player-name") %>% html_attr("href") %>% as.character()
Players
> library(XML)
> library(rvest)
Loading required package: xml2
Attaching package: ‘rvest’
The following object is masked from ‘package:XML’:
xml
> match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
> WSm <- read_html(match)
> Players <- WSm %>% html_nodes(".player-name") %>% html_attr("href") %>% as.character()
> Players
[1] "/fotballdata/person/profil/?fiksId=2820074" "/fotballdata/person/profil/?fiksId=2775969"
[3] "/fotballdata/person/profil/?fiksId=2774767" "/fotballdata/person/profil/?fiksId=2820044"
[5] "/fotballdata/person/profil/?fiksId=2820232" "/fotballdata/person/profil/?fiksId=2820027"
[7] "/fotballdata/person/profil/?fiksId=2820034" "/fotballdata/person/profil/?fiksId=2799892"
[9] "/fotballdata/person/profil/?fiksId=2820237" "/fotballdata/person/profil/?fiksId=2799883"
[11] "/fotballdata/person/profil/?fiksId=2847997" "/fotballdata/person/profil/?fiksId=2830200"
[13] "/fotballdata/person/profil/?fiksId=2820235" "/fotballdata/person/profil/?fiksId=2779315"
[15] "/fotballdata/person/profil/?fiksId=2820241" "/fotballdata/person/profil/?fiksId=2799908"
[17] "/fotballdata/person/profil/?fiksId=2820240" "/fotballdata/person/profil/?fiksId=2860570"
[19] "/fotballdata/person/profil/?fiksId=2795482" "/fotballdata/person/profil/?fiksId=2764974"
[21] "/fotballdata/person/profil/?fiksId=2795481" "/fotballdata/person/profil/?fiksId=2794122"
[23] "/fotballdata/person/profil/?fiksId=2852202" "/fotballdata/person/profil/?fiksId=2863826"
[25] "/fotballdata/person/profil/?fiksId=2811850" "/fotballdata/person/profil/?fiksId=2863824"
[27] "/fotballdata/person/profil/?fiksId=2800983" "/fotballdata/person/profil/?fiksId=2867153"
[29] "/fotballdata/person/profil/?fiksId=2811916" "/fotballdata/person/profil/?fiksId=2780695"
[31] "/fotballdata/person/profil/?fiksId=2811908" "/fotballdata/person/profil/?fiksId=2980432"
[33] "/fotballdata/person/profil/?fiksId=2904191" "/fotballdata/person/profil/?fiksId=2806897"
[35] "/fotballdata/person/profil/?fiksId=2794123"
我已经抓取了一些网站,但我的输出并没有真正的问题,但我不明白为什么在这个特定的网站上我只得到了我试图抓取的第一个实例,而不是所有的36.
我正在尝试收集页面上所有玩家的 href
链接并将它们保存到列表或数据框中。
我当前的代码是:
library(XML)
library(rvest)
match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
WSm <- read_html(match)
Players <- WSm %>% html_node(".player-name") %>% html_attr("href") %>% as.character()
这给了我:
[1] "/fotballdata/person/profil/?fiksId=2820074"
并非我所期望的所有玩家的所有 href
的完整列表。有人能帮忙吗?
使用 html_nodes() 而不是 html_node()
library(XML)
library(rvest)
match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
WSm <- read_html(match)
Players <- WSm %>% html_nodes(".player-name") %>% html_attr("href") %>% as.character()
Players
> library(XML)
> library(rvest)
Loading required package: xml2
Attaching package: ‘rvest’
The following object is masked from ‘package:XML’:
xml
> match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922"
> WSm <- read_html(match)
> Players <- WSm %>% html_nodes(".player-name") %>% html_attr("href") %>% as.character()
> Players
[1] "/fotballdata/person/profil/?fiksId=2820074" "/fotballdata/person/profil/?fiksId=2775969"
[3] "/fotballdata/person/profil/?fiksId=2774767" "/fotballdata/person/profil/?fiksId=2820044"
[5] "/fotballdata/person/profil/?fiksId=2820232" "/fotballdata/person/profil/?fiksId=2820027"
[7] "/fotballdata/person/profil/?fiksId=2820034" "/fotballdata/person/profil/?fiksId=2799892"
[9] "/fotballdata/person/profil/?fiksId=2820237" "/fotballdata/person/profil/?fiksId=2799883"
[11] "/fotballdata/person/profil/?fiksId=2847997" "/fotballdata/person/profil/?fiksId=2830200"
[13] "/fotballdata/person/profil/?fiksId=2820235" "/fotballdata/person/profil/?fiksId=2779315"
[15] "/fotballdata/person/profil/?fiksId=2820241" "/fotballdata/person/profil/?fiksId=2799908"
[17] "/fotballdata/person/profil/?fiksId=2820240" "/fotballdata/person/profil/?fiksId=2860570"
[19] "/fotballdata/person/profil/?fiksId=2795482" "/fotballdata/person/profil/?fiksId=2764974"
[21] "/fotballdata/person/profil/?fiksId=2795481" "/fotballdata/person/profil/?fiksId=2794122"
[23] "/fotballdata/person/profil/?fiksId=2852202" "/fotballdata/person/profil/?fiksId=2863826"
[25] "/fotballdata/person/profil/?fiksId=2811850" "/fotballdata/person/profil/?fiksId=2863824"
[27] "/fotballdata/person/profil/?fiksId=2800983" "/fotballdata/person/profil/?fiksId=2867153"
[29] "/fotballdata/person/profil/?fiksId=2811916" "/fotballdata/person/profil/?fiksId=2780695"
[31] "/fotballdata/person/profil/?fiksId=2811908" "/fotballdata/person/profil/?fiksId=2980432"
[33] "/fotballdata/person/profil/?fiksId=2904191" "/fotballdata/person/profil/?fiksId=2806897"
[35] "/fotballdata/person/profil/?fiksId=2794123"