用curl登录

时间:2013-01-11 15:57:23

标签: php curl

我想从谷歌图书(我定期购买)下载一本书,以便离线阅读(不幸的是,这个选项不适用于我的书)。 我想创建一个脚本,我将页面拉出来,然后将它们保存为pdf ... 我不认为有任何违法行为,因为我付了.. 我尝试使用curl,但您看到的页面未经过身份验证。 我当时写道:

function leggiUrl($url,$data){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}
$page=leggiUrl("https://www.google.com/accounts/ServiceLoginAuth", array("Email" => "mia_mail@gmail.com", "Passwd" => "miapassword"));
echo $page;

很遗憾地向我显示了google的登录页面...因为它没有登录?

1 个答案:

答案 0 :(得分:0)

如果你看一下https://www.google.com/accounts/ServiceLoginAuth的来源,你会看到一堆隐藏的字段。谷歌期待这些字段以允许登录。您需要查看使用Oauth 2登录Google的方法,直接POST不会这样做: https://developers.google.com/accounts/docs/OAuth2