在R中构建迭代URL时转义“%”

时间:2019-01-15 15:37:27

标签: r string web-scraping special-characters

我正在尝试在R中构建URL来进行一些Web抓取。当我的URL需要使用“%”时,出现错误。以下是我的代码的一次迭代尝试执行的示例。下面也是构建完整URL时的样子:

https://247sports.com/Season/2017-Football/CompositeRecruitRankings/?ViewPath=~%2FViews%2FSkyNet%2FPlayerSportRanking%2F_SimpleSetForSeason.ascx&InstitutionGroup=HighSchool&Page=2

我曾尝试使用\来转义%符号,但我也引用了以下链接,但未能使其针对我的情况成功运行:

URL Escaping in R How do I deal with special characters like \^$.?*|+()[{ in my regex?

NULL

运行此命令时,出现以下错误:

link <- "https://247sports.com/Season/"
year<-2018
team<-"PrepSchool"
year_url <- sprintf(link, year)
year_url2 <- str_c(year_url, "-Football/CompositeRecruitRankings/?ViewPath=~%2FViews%2FSkyNet%2FPlayerSportRanking%2F_SimpleSetForSeason.ascx&InstitutionGroup=%s")
team_url <- sprintf(year_url2, team)
team_url2<-str_c(team_url,"&page=%i")

修改后的网址

0 个答案:

没有答案