How to get a page from another site using PHP

-1
Hello, I'm trying to get prices for a page on the iFood website using PHP so that if my client changes the prices he placed on their page, the site already does the automatic correction. The problem is that nothing I try works. I'm using file_get_contents() and it still does not load. Ex:

$contents = file_get_contents('https://www.ifood.com.br/delivery/belo-horizonte-mg/puro-sabor-salgados---carlos-prates-carlos-prates');
print_r($contents);

Does anyone know in any way that I can capture this page? I just need to pull the contents of it to a variable that the rest I do the treatment ...

    
asked by anonymous 30.06.2018 / 00:19

1 answer

-1

I've been looking at Ifood's website. What happens is that the site detects which browser is requesting the page before sending the content. When it identifies that it is PHP, it returns an error.

I tried to circumvent the process with a Stream but it also did not work.

<?php

// configura o stream e as opções de Headers(cabeçalhos)
$stream = stream_context_create(
Array("http" => Array("method"  => "GET", 
  "timeout" => 30, 
  "header"  => "User-agent:".$_SERVER['HTTP_USER_AGENT'],
  "Accept"=> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding"=> " gzip, deflate, br",
"Accept-Language"=> " pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control"=> " max-age=0",
"Connection"=> " keep-alive",
"Host"=> " www.ifood.com.br",
"Upgrade-Insecure-Requests"=> 1
                                ))); 


if ( $arquivo = fopen("https://www.ifood.com.br/delivery/belo-horizonte-mg/puro-sabor-salgados---carlos-prates-carlos-prates", 'r', false, $stream) ) { 
} 

while(!feof($arquivo))
  {
   //Mostra uma linha do arquivo
   $linha = fgets($arquivo);
   echo $linha;
  }?> 
    
30.06.2018 / 18:32