首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >php curl登录到espn.com

php curl登录到espn.com
EN

Stack Overflow用户
提问于 2018-06-30 00:17:57
回答 1查看 675关注 0票数 -1

我尝试了这么多不同的事情,但没有找到任何解决方案,以便使用cUrl登录到http://www.espn.com/login/,登录后,我想检索一个受保护的密码区http://games.espn.com/ffl/clubhouse?leagueId=93772&teamId=1&seasonId=2018

我尝试使用的是:

代码语言:javascript
复制
$username = 'email';
$password = 'password!';
$loginUrl = 'http://www.espn.com/login/';

//init curl
$ch = curl_init();

//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);

// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);

//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password);

//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//execute the request (the login)
$store = curl_exec($ch);

//the login is now done and you can continue to get the
//protected content.
sleep(3);
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'http://games.espn.com/ffl/clubhouse?leagueId=93772&teamId=1&seasonId=2018');

//execute the request
$content = curl_exec($ch);

curl_close($ch);

//save the data to disk
file_put_contents('download.txt', $content);

但是脚本登录后再也没有检索到html!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51105853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档