使用Curl登录meetup.com [英] Logging in to meetup.com with Curl

查看:137
本文介绍了使用Curl登录meetup.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试自动登录www.meetup.com,但没有取得多少成功: -

I'm trying to automatically log in to www.meetup.com without much success:-

这是我的代码: -

This is my code:-

      <?
$username="my@email.com";
$password="123abc";
$url="http://meetup.com";
$cookie="cookie.txt";

$postdata = "email=". $username ."&password=". $password . "&submitButton=Login";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "/login");

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, "http://www.meetup.com/");

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;

exit;
?> 

没有快乐 - 任何想法?

No joy - any ideas?

感谢

Jonathan

推荐答案

第一页载入

尝试使用CURLOPT_COOKIEJAR发出请求,然后使用CURLOPT_COOKIEFILE和CURLOPT_COOKIEJAR

try making a request with CURLOPT_COOKIEJAR and then make the login request using CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR

发出登录请求对于地狱,这是一个函数,我使请求看起来更清洁

also for the hell of it, this is a function i make to make requests look cleaner

function curl_http_request ($url, $options)
{
    $handle = curl_init($url);
    curl_setopt_array($handle, $options);
    ob_start();
    $buffer = curl_exec($handle);
    ob_end_clean();
    curl_close($handle);
    return $buffer;
}

使用示例

$options = array(
    CURLOPT_RETURNTRANSFER => TRUE
);

curl_http_request($url, $options);

这应该可以工作

// set global curl options
$curloptions = array(
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
        CURLOPT_TIMEOUT => 60,
        CURLOPT_COOKIEJAR => $cookie,
        CURLOPT_COOKIEFILE => $cookie,
        CURLOPT_REFERER => 'http://www.meetup.com/'
);

// set userinfo
$username = 'bobsmit@gmail.com';
$password = 'bobsmit@gmail.com';
$cookie = 'cookie.txt';

// clear cookie.txt (fresh session)
$handle = fopen($cookie, 'w');
fclose($handle);

// make a dummy request to generate a session
curl_http_request('http://www.meetup.com/login/', $curloptions);

// login
curl_http_request('http://www.meetup.com/login/', 
    array(
        CURLOPT_POSTFIELDS => 'email=' . urlencode($username) . '&password=' . urlencode($password) . '&rememberme=on&submitButton=Login&returnUri=http%3A%2F%2Fwww.meetup.com%2F&op=login',
        CURLOPT_POST => TRUE
    ), $curloptions
);

//example request
echo curl_http_request('http://www.meetup.com/account/', 
    array(
        CURLOPT_FOLLOWLOCATION => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE
    ), $curloptions
);

function curl_http_request ($url, $moreoptions = array(), $options = array())
{
    foreach ($moreoptions as $k => $v) $options[$k] = $v;
  $handle = curl_init($url);
  curl_setopt_array($handle, $options);
  ob_start();
  $buffer = curl_exec($handle);
  ob_end_clean();
  curl_close($handle);
  return $buffer;
}

希望这个工作原理:)

这篇关于使用Curl登录meetup.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆