使用PHP中的Curl从网站获取请求Cookie

时间:2019-05-16 04:07:55

标签: php curl web-scraping

我想使用PHP中的curl方法从网站获取请求Cookie。这有可能吗?我尝试用curl,但是它只是得到一个响应Cookie,而且我不知道请求Cookie的工作方式。有人可以帮我吗?

示例代码:

<?php
$url = "https://www.ebay.com/";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$response = curl_exec($ch);


  $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  $headers = substr($response, 0, $header_size);
  $body = substr($response, $header_size);

curl_close($ch);


print($headers)
?>

我想基于屏幕截图获取请求cookie:

screenshot

0 个答案:

没有答案
相关问题