准备
https://github.com/FriendsOfPHP/Goutte
https://github.com/guzzle/guzzle
https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html
安装
composer require fabpot/goutte
composer require guzzlehttp/guzzle
试试
先看看 goutte
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'https://www.yuepaibao.com/moments');
$crawler->filter('.content span')->each(function ($node) {
print $node->text()."\n";
});
**再看看 GuzzleHttp **
use GuzzleHttp\Client as GoutteClient;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
$url = 'https://www.hao123.com';
$request = new GuzzleRequest('GET', $url);
$client = new GoutteClient();
$response = $client->send($request, ['timeout' => 5]);
$content = $response->getBody()->getContents();
echo $content;