使用RVest访问多个链接

时间:2019-07-13 06:13:09

标签: r

我有一个代码可以从网站上检索信息。我想使用代码从多个链接中检索信息。但是我遇到了错误

function1<- function (urlbase){
webpage <- read_html(urlbase)
countries_html <- html_nodes(webpage, ".cscore_name--long")
countries <- html_text(countries_html)

mom_html <- html_nodes(webpage, ".gp__cricket__player- 
match__player__detail__link span")
mom <- html_text(mom_html)

margin_html <- html_nodes(webpage, ".cscore_notes_game")
margin <- html_text(margin_html)


cricket <- data.frame(Countries = countries, MOM = mom, Margin = margin, Toss 
= toss, Venue= venue, Scores= scores, Extras= extras)
return(cricket)
}

urlbase <- c("https://www.espncricinfo.com/series/16961/scorecard/64201/new- 
zealand-vs-england-1st-odi-england-tour-of-new-zealand-1982-83", 
"https://www.espncricinfo.com/series/16961/scorecard/64202/new-zealand- 
vs-england-2nd-odi-england-tour-of-new-zealand-1982-83")

function1(urlbase)

Error in doc_parse_file(con, encoding = encoding, as_html = as_html, 
options = options) : 
Expecting a single string value: [type=character; extent=2]. 

我了解这是因为我在urlbase中使用了字符串,但是我不知道其背后的原因以及如何使代码正常工作。

0 个答案:

没有答案