Php 使用curl登录

Php 使用curl登录,php,curl,Php,Curl,我想从GoogleBooks下载一本书,我经常购买它来离线阅读。不幸的是,我的书没有这个选项。 我想创建一个脚本,我拉出来的网页,然后保存在pdf他们。。。 我不认为有什么违法的,因为我付钱了。。 我尝试使用curl,但您看到的页面没有经过身份验证。 我当时写道: function leggiUrl($url,$data){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST,true); curl_setopt($c

我想从GoogleBooks下载一本书,我经常购买它来离线阅读。不幸的是,我的书没有这个选项。 我想创建一个脚本,我拉出来的网页,然后保存在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;

不幸的是,我看到了谷歌的登录页面。。。因为它没有登录?

如果您查看https://www.google.com/accounts/ServiceLoginAuth 您将看到一组隐藏字段。谷歌希望这些字段能够允许登录。您需要看看使用Oauth 2登录Google的方法,一篇直接的帖子是不行的:

您可能应该使用cookies。。。看看CURLOPT_COOKIEFILE和CURLOPT_COOKIEJAR@glavic:-1。postfields将乐于接受一个名称/值对数组,并为您查询它。