PHP - 通过表单登录并抓取cookie

时间:2017-02-07 03:14:19

标签: php forms cookies login amazon

我尝试登录以下网址:pitangui.amazon.com

我尝试过使用cURL以及像https://barebonescms.com/documentation/ultimate_web_scraper_toolkit/

这样的库

但是,我通过亚马逊使用webscraper收到以下错误:

Amazon Error

这是我的PHP代码:

<?php
    require_once "support/http.php";
    require_once "support/web_browser.php";
    require_once "support/simple_html_dom.php";

    $url = "https://pitangui.amazon.com";
    $web = new WebBrowser(array("extractforms" => true));
    $result = $web->Process($url);

    if (!$result["success"])  echo "Error retrieving URL.  " . $result["error"] . "\n";
    else if ($result["response"]["code"] != 200)  echo "Error retrieving URL.  Server returned:  " . $result["response"]["code"] . " " . $result["response"]["meaning"] . "\n";
    else
    {   

        $form = $result["forms"][0];

        $form->SetFormValue("email", "myemail@gmail.com");
        $form->SetFormValue("password", "mypass");

        $result2 = $form->GenerateFormRequest("signIn");

        $result = $web->Process($result2["url"], "auto", $result2["options"]);

        if (!$result["success"])  echo "Error retrieving URL.  " . $result["error"] . "\n";
        else if ($result["response"]["code"] != 200)  echo "Error retrieving URL.  Server returned:  " . $result["response"]["code"] . " " . $result["response"]["meaning"] . "\n";
        else
        {
            // Do something with the results page here...
            print_r($result);
        }
    }
?>

我首先尝试让登录工作,然后我将通过$ _SERVER [&#39; Cookie&#39;]

获取Cookie

1 个答案:

答案 0 :(得分:0)

添加

$form->SetFormValue("create","0");