Why bestbuy.com can't be scraped with PHP?

115 Views Asked by At

I tried to create a scraper for bestbuy.com but it seems that PHP can't scrape BestBuy.

To test, I tried the same piece of code on amazon and other pages and it returns the page title. Which means that the code works. Yet, BestBuy can't be accessed with PHP.

This is the code I used to get the title:

$content = file_get_contents('https://www.bestbuy.com/');
$select= preg_match("/<title>(?<title>.+)<\/title>/m",$content,$title);
echo $title['title'];

I was expecting it to output BestBuy website title but it gave this error:

Warning: file_get_contents(https://www.bestbuy.com/): Failed to open stream: HTTP request failed! in C:\xampp\htdocs\internshipPHP\Assignment#4\scraper.php on line 3

Do you have any idea?

0

There are 0 best solutions below