0

I am trying to get data from the amazon product page. But the search for the price always result in The current node list is empty. . The other elements like title are present in the result.

            $jar = new CookieJar();
            $url = "https://www.amazon.com/Simple-Mobile-Prepaid-Midnight-Carrier/dp/B07XSQT4Q3";
            $client = new Client([
                'cookies' => $jar,
                'headers' => [
                    'Host' => 'www.amazon.com',
                    'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.3',
                    'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                    'Accept-Language' => 'en-US,en;q=0.5',
                    'Accept-Encoding' => 'gzip, deflate, br',
                    'Connection' => 'keep-alive',
                    'Upgrade-Insecure-Requests' => '1',
                    'Cache-Control' => 'max-age=0',
                    'TE' => 'Trailers',
                ],
            ]);

$response = $client->request('GET', $url);
$crawler = new Crawler($response->getBody()->getContents());
$title = $crawler->filter('#productTitle')->text('Product Title couldn\'t be extracted', true);
$price = $crawler->filter('#priceblock_ourprice')->text('Product Price couldn\'t be extracted', true);

If trying to run this request with postman the price is present.

serj
  • 193
  • 1
  • 3
  • 19

1 Answers1

0

The problem was that price was not always present on the page depends on your location, after updating to Symfony 4.4 the problem was solved and it started to return Product Price couldn\'t be extracted instead of crashing.

serj
  • 193
  • 1
  • 3
  • 19