首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Cookies“添加到购物车”的刮刮Magento网站

使用Cookies“添加到购物车”的刮刮Magento网站
EN

Stack Overflow用户
提问于 2016-02-04 13:13:19
回答 1查看 189关注 0票数 0

我在刮这个URL

我想刮掉这个项目的数量。

为此,我的策略是尝试添加quantity和POST表单,直到出现错误,指出”"xyz产品所需的数量“是不够的。

我试着用file_get_contents();echo发布表单输出,它返回一个错误页面,上面写着Cookies must be enabled in your browser

下面是我的发帖方式

代码语言:javascript
运行
复制
    $postdata = http_build_query(
            array(
                'product' => $prod_id,
                'qty' => 5,
                'related_product' => ''
            )
    );

    $opts = array('http' =>
        array(
            'method' => 'POST',
            'header' => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );

    $context = stream_context_create($opts);

    $result = file_get_contents($action_url, false, $context);

我也尝试过使用cURL

$cookieFile = tempnam(null,'SMS');$userAgent = 'Mozilla/5.0 (X11;Ubuntu;Linux x86_64;rv:11.0) Gecko/20100101 Firefox/11.0';

代码语言:javascript
运行
复制
    $cookieFile = tempnam(null, 'SMS');
    $userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $action_url);

    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
    $post = array(
        'product' => $prod_id,
        'qty' => 5,
        'related_product' => '');

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    $html = curl_exec($ch);

但是我还是从那个网站上得到了错误,那就是应该在浏览器中启用Cookies。

因此,我的问题是如何使用将产品添加到购物车中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-08 19:27:41

我终于用Guzzle Goutte做了

它接收任何服务器发送的cookie。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35201948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档