我在刮这个URL。
我想刮掉这个项目的数量。
为此,我的策略是尝试添加quantity和POST表单,直到出现错误,指出“”"xyz产品所需的数量“是不够的。
我试着用file_get_contents();
和echo
发布表单输出,它返回一个错误页面,上面写着Cookies must be enabled in your browser
下面是我的发帖方式
$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';
$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。
因此,我的问题是如何使用?将产品添加到购物车中。
发布于 2016-02-08 19:27:41
我终于用Guzzle Goutte
做了
它接收任何服务器发送的cookie。
https://stackoverflow.com/questions/35201948
复制相似问题