我正在尝试使用R在ESPN的一个受密码保护的网站后面进行Webscrape



我正试图使用R从ESPN网络抓取一些数据,但我在登录时遇到了问题。我不知道是因为ESPN阻止了网络直播,还是我错过了什么。这是我的代码:

library(rvest)
url = "https://fantasy.espn.com/football/league/draftrecap?seasonId=2015&leagueId=1734728"
pgsession<-html_session(url)
read_html(url) #to make sure I am in the ESPN login page not the league page

经过这一步,我想我错了。我不知道如何找到登录所需的正确表格

fantform    <-html_form(pgsession)[[1]]
fantform #to check the form I have

我通过查看此表格得到的回复如下。这似乎不对,但如果我更改表格编号,我会得到一个";错误:下标越界">

<form> '<unnamed>' (GET )
<field> (search) : 

我剩下的代码在下面,但我很确定我被困在了这一部分。

filled_form <- html_form_set(pgform, "usernanerow" = "username", "passwordrow" = "password")
submit_form(pgsession,filled_form)
Fantasy_league <- jump_to(pgsession, "https://fantasy.espn.com/football/league/draftrecap?seasonId=2015&leagueId=1734728")

我非常感谢所有的回复/帮助。提前谢谢!

它们似乎真的很难找到登录页面,因此很难找到登陆表单,就像你说的那样,上面的表单不正确。如果你能找到登录页面,那么只需将你的第一个url替换为登录页面的url。

除此之外,其余代码都是正确的

如果你很乐意使用现有的软件包,那么似乎已经有一个软件包可以帮助你:

https://cran.r-project.org/web/packages/fflr/vignettes/fantasy-football.html

相关内容

最新更新