如何使用PHP cURL登录Amazon [英] How can I login in Amazon with PHP cURL

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

问题描述

我需要登录到Amazon页面: https://sellercentral-japan.amazon.com/gp/sign-in/sign-in.html/ref=pt_login_lgin_login 与PHP cURL(无Amazon Web服务)。



下面是代码如何尝试:

  const AMAZON_LOGIN_URL =https:// sellercentral-japan .amazon.com / gp / sign-in / sign-in.html / ref = pt_login_lgin_login; 

$ this-> crawler = new crawler();
//使用Amazon帐户登录
$ parameters ='protocol = https& action = sign-in& email ='self:AMAZON_USER。'& password ='self:AMAZON_PWD;
$ status = $ this-> crawler-> logIn(self :: AMAZON_LOGIN_URL,$ parameters);

/ *在爬网类* /
//用于登录。
function logIn($ loginActionUrl,$ parameters){
$ strCookie ='D:\public_html\project\cookie.txt';

curl_setopt($ this-> curl,CURLOPT_URL,$ loginActionUrl);
curl_setopt($ this-> curl,CURLOPT_POST,1);
curl_setopt($ this-> curl,CURLOPT_POSTFIELDS,$ parameters);

curl_setopt($ this-> curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ this-> curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ this-> curl,CURLOPT_USERAGENT,$ _SERVER ['HTTP_USER_AGENT']);
curl_setopt($ this-> curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ this-> curl,CURLOPT_HEADER,0);

curl_setopt($ this-> curl,CURLOPT_COOKIEJAR,$ strCookie);
curl_setopt($ this-> curl,CURLOPT_COOKIEFILE,$ strCookie);

$ content = curl_exec($ this-> curl);
return $ content;
}

作为回应,我得到登录页面,出现错误信息:您的登录会话已过期,请重新登录。
此消息还显示:



找不到



请求的URL / aan / 2009-09-09 / static / amazon / iframeproxy-12.html在此服务器上找不到。



我尝试过大多数在网络上找到的解决方案。
这个解决方案是有希望但仍然不工作:
PHP Curl - Cookie问题< a>
我更改了所需的登录页面网址,并进行了一些其他更改,但它给出此错误:



尝试执行此操作时出错。请在15分钟后重试。
即使15分钟后,也会出现同样的错误。



如果任何人可以帮助,这将是一个帮助。



谢谢。

解决方案

只要标记为答案:


  • 使用新工作阶段传送登入资料,以及使用新工作阶段传送登入资料。 隐藏输入

  • 以查看脚本: http://stackoverflow.com/a/7532730/889678


    I need to login to Amazon page: https://sellercentral-japan.amazon.com/gp/sign-in/sign-in.html/ref=pt_login_lgin_login with PHP cURL (without Amazon Web Service).

    Here is code how I tried for that:

    const AMAZON_LOGIN_URL = "https://sellercentral-japan.amazon.com/gp/sign-in/sign-in.html/ref=pt_login_lgin_login";
    
    $this->crawler = new crawler();        
    // login with Amazon account
    $parameters ='protocol=https&action=sign-in&email='.self::AMAZON_USER.'&password='.self::AMAZON_PWD;
    $status = $this->crawler->logIn(self::AMAZON_LOGIN_URL, $parameters);
    
    /* in crawler class */
    //This is used for login.
    function logIn($loginActionUrl, $parameters) {
        $strCookie = 'D:\public_html\project\cookie.txt';
    
        curl_setopt($this->curl, CURLOPT_URL, $loginActionUrl);
        curl_setopt($this->curl, CURLOPT_POST, 1);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $parameters);
    
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($this->curl, CURLOPT_HEADER, 0);
    
        curl_setopt($this->curl, CURLOPT_COOKIEJAR, $strCookie);
        curl_setopt($this->curl, CURLOPT_COOKIEFILE, $strCookie);
    
        $content = curl_exec($this->curl);
        return $content;
    }
    

    As a response, I get login page with error message: "Your login session expired. Please sign in again." And this message is also displayed:

    "Not Found

    The requested URL /aan/2009-09-09/static/amazon/iframeproxy-12.html was not found on this server."

    I have tried most of the solutions found on web. This solution was hopeful but still not working: PHP Curl - Cookies problem I have changed required login page URL and made few other changes but it give this error:

    "There was an error trying to perform this operation. Please try again in 15 minutes." even after 15 min, it gives the same error.

    If anybody can help, it would be help.

    Thanks.

    解决方案

    Just for marking as answer:
    you have to 2 things:

    1. Request login page from server using get method
    2. Send login data using new session and with hidden inputs

    to see the script : http://stackoverflow.com/a/7532730/889678

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

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