cURL / Mailing Lists / curl-library / Single Mail

curl-library

Google login (cookie turned off)

From: Kim Kristensen <Kim.Kristensen_at_omnicommediagroup.com>
Date: Fri, 21 Oct 2011 10:42:36 -0400

Hi guys,

Can you help me out here?

I've tried to make a script that automatically login at google at can scrape their "local business center" data. I need it to simplify reporting.

I've used HTTPliveheader but keep getting this error, and I'm not logged in: "Your browser's cookie functionality is turned off. Please turn it on."

This is my code, can you see any errors? I would really appreciate if you can help me out here - I've given up :\

<?
require("functions/functions.php");
require("functions/simple_html_dom.php");

// ------------------------------------------------------------------------------------- STEP 1

$GooglePlacesStart = "https://www.google.com/accounts/ServiceLogin?service=lbc&continue=https://www.google.com/local/add%3Fservice%3Dlbc";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $GooglePlacesStart);
curl_setopt($ch, CURLOPT_HEADER, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '30');
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookies.txt');

/*curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyport);*/

$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);
//curl_close($curl);

echo "<br/><br/>1. step completed<br/><br/>";

// ------------------------------------------------------------------------------------- STEP 2

$html = str_get_html($result['EXE']);

$dsh;
$GALX;

foreach($html->find('input[@type=hidden]') as $e)
{
                             $name = $e->name;
                             $value = $e->value;
                             echo "<br/>input: ".$name."=".$value;
                                                          //if($items->item($i)->hasAttribute()
                                                          //echo "input: ".$items->item($i)->nodeValue . "<br/>";

                             if($name=="dsh")
                             {
                                                          $dsh = $value;
                             }elseif($name=="GALX"){
                                                          $GALX = $value;
                             }
}

$fields = array(
            'pstMsg'=>urlencode('1'),
            'dnConn'=>'https%3A%2F%2Faccounts.youtube.com',
            'continue'=>'http%3A%2F%2Fwww.google.com%2Flocal%2Fadd%2FbusinessCenter%3Fhl%3Den-US%26gl%3DUS',
                                                                                       'followup'=>'http%3A%2F%2Fwww.google.com%2Flocal%2Fadd%2FbusinessCenter%3Fhl%3Den-US%26gl%3DUS',
            'service'=>'lbc',
            'dsh'=>urlencode($dsh),
                                                                                       'hl'=>'en-US',
            'timeStmp'=>'',
            'secTok'=>'',
                                                                                       'GALX'=>urlencode($GALX),
                                                                                       'Email'=>'mail%40gmail.com',
                                                                                       'Passwd'=>'password',
                                                                                       'rmShown'=>'1',
                                                                                       'signIn'=>'Sign+in',
                                                                                       'asts'=>''

        );
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
//echo "<br/>fields:".$fields_string;
$fields_string = rtrim($fields_string,'&');

echo "<br/>fields:".$fields_string;
echo "<br/>fields:pstMsg=1&dnConn=https%3A%2F%2Faccounts.youtube.com&continue=http%3A%2F%2Fwww.google.com%2Flocal%2Fadd%2FbusinessCenter%3Fhl%3Den-US%26gl%3DUS&followup=http%3A%2F%2Fwww.google.com%2Flocal%2Fadd%2FbusinessCenter%3Fhl%3Den-US%26gl%3DUS&service=lbc&dsh=2659499923465577641&hl=en-US&timeStmp=&secTok=&GALX=OLMY2kzhhpM&Email=mail%40gmail.com&Passwd=password&rmShown=1&signIn=Sign+in&asts=";

curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/accounts/ServiceLoginAuth');
curl_setopt($ch, CURLOPT_HEADER, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '30');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/accounts/ServiceLogin?service=lbc&continue=https://www.google.com/local/add%3Fservice%3Dlbc');
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookies.txt');

curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

/*curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyport);*/

$result['EXE'] = curl_exec($ch);
//$result['INF'] = curl_getinfo($ch);
//$result['ERR'] = curl_error($ch);
//curl_close($curl);

//echo $result['INF'];
print_r($result);

echo "<br/><br/>2. step completed<br/><br/>";

// ------------------------------------------------------------------------------------- STEP 3

curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/local/add/businessCenter?hl=en-US&gl=US&pli=1');
curl_setopt($ch, CURLOPT_HEADER, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '30');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/accounts/ServiceLogin?service=lbc&continue=https://www.google.com/local/add%3Fservice%3Dlbc');
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookies.txt');

/*curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyport);*/

$result['EXE'] = curl_exec($ch);
//$result['INF'] = curl_getinfo($ch);
//$result['ERR'] = curl_error($ch);
curl_close($ch);
unlink('tmp/cookies.txt');
echo $result['EXE'];

echo "<br/><br/>3. step completed<br/><br/>";
?>

______________________________________________________________________
This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. Dissemination, distribution or copying of this e-mail or the information herein by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is prohibited. If you have received this e-mail in error, please immediately notify us by calling our Help Desk at (212)590-7600, or e-mail to helpdeskus_at_omnicommediagroup.com.
______________________________________________________________________

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-10-21