HTML treatment with Guzzle Laravel?

1

I have an application that needs to read external data, ie another URL , I'm necessarily doing it with Guzzle , but when I convert to json to mount the array with the data, it returns null.

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;


class salarioController extends Controller
{

  public function index()
  {
     $client =  new Client();
     $response = $client->get('http://www.guiatrabalhista.com.br/guia/salario_minimo.htm');
     $body = json_decode($response->getBody(), TRUE);
  }
}

The result of $body is empty.

    
asked by anonymous 13.08.2018 / 01:55

1 answer

-1

At the moment I have this code using Guzzle + Goutte, but this one giving error of: "Class 'DOMDocument' not found"

namespace App\Http\Controllers;

use Illuminate \ Http \ Request; use Goutte \ Client; use GuzzleHttp \ Client as GuzzleClient;

class ExtractController extends Controller {

public function index(){

    $goutteClient = new Client();
    $guzzleClient = new GuzzleClient(array(
                        'timeout' => 6000,));

    $goutteClient->setClient($guzzleClient);

    $crawler = $goutteClient->request('GET', 'http://www.cophieu68.vn/stockonline_node.php?stcid=1');

    $news = $crawler->filterXPath('//table[@id="board_online"]')->filter('tr')->each(function ($tr, $i) { return $tr->filter('td')->each(function ($td, $i) { return trim($td->text()); }); });

    return $news;
}

}

    
13.08.2018 / 19:03