使用 httr R 包发送 POST 请求
Send a POST request using httr R package
在通过 POST 请求发送服务器数据时,我不知道如何模仿浏览器的行为。以下是相关的 URL,下面有解释。
(1) http://kenpom.com/
(2) http://kenpom.com/register.php?frompage=1
<form id="login" method="POST" action="handlers/login_handler.php">
<label>E-mail </label><input type="text" name="email" />
<label>Password </label><input type="password" name="password" />
<input type="submit" name="submit" value="Login!" />
(3) http://kenpom.com/team.php?team=Rice
(1) 主页(select 未登录时的团队页面,重定向 -> (2) )
(2) 登录页面(成功登录后重定向到团队特定页面)
(3) 团队特定页面:例如米饭
url <- ("http://kenpom.com/team.php?team=Rice")
login <- list(
email = "login",
password = "password"
)
teampage <- POST(url, body = login)
Response [http://kenpom.com/register.php?frompage=1]
Date: 2015-03-07 23:04
Status: 200
Content-Type: text/html
Size: 7.45 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<LINK REL=stylesheet TYPE="text/css" HREF="css/rate.css?1414365416">
<TITLE>kenpom.com subscription</TITLE>
最终想使用 rvest 包抓取一些信息,但在尝试抓取时得到的结果是空的:http://kenpom.com/register.php?frompage=1
尝试
library(httr)
login <- list(
email = "login",
password = "password",
submit = "Login!"
)
res <- POST("http://kenpom.com/handlers/login_handler.php", body = login, encode = "form", verbose())
team <- GET("http://kenpom.com/team.php?team=Rice", verbose())
在通过 POST 请求发送服务器数据时,我不知道如何模仿浏览器的行为。以下是相关的 URL,下面有解释。
(1) http://kenpom.com/
(2) http://kenpom.com/register.php?frompage=1
<form id="login" method="POST" action="handlers/login_handler.php">
<label>E-mail </label><input type="text" name="email" />
<label>Password </label><input type="password" name="password" />
<input type="submit" name="submit" value="Login!" />
(3) http://kenpom.com/team.php?team=Rice
(1) 主页(select 未登录时的团队页面,重定向 -> (2) )
(2) 登录页面(成功登录后重定向到团队特定页面)
(3) 团队特定页面:例如米饭
url <- ("http://kenpom.com/team.php?team=Rice")
login <- list(
email = "login",
password = "password"
)
teampage <- POST(url, body = login)
Response [http://kenpom.com/register.php?frompage=1]
Date: 2015-03-07 23:04
Status: 200
Content-Type: text/html
Size: 7.45 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<LINK REL=stylesheet TYPE="text/css" HREF="css/rate.css?1414365416">
<TITLE>kenpom.com subscription</TITLE>
最终想使用 rvest 包抓取一些信息,但在尝试抓取时得到的结果是空的:http://kenpom.com/register.php?frompage=1
尝试
library(httr)
login <- list(
email = "login",
password = "password",
submit = "Login!"
)
res <- POST("http://kenpom.com/handlers/login_handler.php", body = login, encode = "form", verbose())
team <- GET("http://kenpom.com/team.php?team=Rice", verbose())