0

I have this code to scrape bestbuy's website:

<?php
$useragent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
$curl_handle=curl_init('https://www.bestbuy.com/');
curl_setopt($curl_handle, CURLOPT_URL,'https://www.bestbuy.com/');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_COOKIE, '');
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, '');
curl_setopt($curl_handle, CURLOPT_USERAGENT, $useragent);
$query = curl_exec($curl_handle);
curl_close($curl_handle);
?>

But I do not know what am I supposed to put between the quotation marks for the cookies in these lines:

curl_setopt($curl_handle, CURLOPT_COOKIE, '');
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, '');

I am a beginner in scraping so I might have more than one mistake in this code so please help me. Thanks.

  • 1
    This [answer](https://stackoverflow.com/a/10289358/231316) and comments are relevant – Chris Haas Mar 07 '22 at 04:49
  • Yes, but what should I include in the cookie file. I don't get that part. – Omar Alsafarti Mar 07 '22 at 12:27
  • For `CURLOPT_COOKIEJAR` you just pass a file and curl will _write_ to that file. You rarely need to do anything else with that file. For `CURLOPT_COOKIEFILE` you also pass a file, and curl with _read_ from it and send with each request. If you set both to the same file, you get some basic general cookie storage similar to your browser. My previous comment includes some caveats as it relates to session information. You only use `CURLOPT_COOKIE` if you have explicit cookies that you want to send. – Chris Haas Mar 07 '22 at 14:49

0 Answers0