有一个网站我想要登录,总是在网上7/24看到,因为用户之间有一个队列,如果你更经常上网,你会更多地在这个队列上前进。我有一个Linux服务器,我打算用于这个原因,但到目前为止,我无法从谷歌找到任何有用的东西。如果你能帮助我,我会很高兴的!
摘要:我的服务器将始终登录网站,即使在凌晨3点我也会在网上看到。
答案 0 :(得分:2)
登录并获取cURL会话(来自Internet的示例代码):
$username = 'myuser';
$password = 'mypass';
$loginUrl = 'http://www.example.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.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/protected/download.zip');
//execute the request
$content = curl_exec($ch);
curl_close($ch);
然后您可以稍后使用此cookie文件,并且可以使用cURL进行GET请求 - 例如每半小时一次。您可能必须在登录之前发出GET请求,如果您尝试登录的站点使用了令牌。 (我在大学的在线学习系统中遇到同样的问题,教授可以看到你看了多久的内容:-D)