使用Laravel Goutte包进行报废

时间:2016-11-08 10:52:04

标签: php laravel web-scraping goutte

但我面临着为我的目标网站报废的问题 它显示了一个错误

"file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:140770FC

:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol"

我的代码:

<?php

namespace App\Http\Controllers;


use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\library\simple_html_dom;

class WebScraperController extends Controller
{
    public function index()
    {
        //  Create a new Goutte client instance
        $client = new Client();

        //  Hackery to allow HTTPS
        $guzzleclient = new \GuzzleHttp\Client([
            'timeout' => 60,
            'verify' => false,
        ]);

        // Create DOM from URL or file
        $html = new \Htmldom('https://www.example.com/');


        foreach ($html->find('img') as $element) {
            echo $element->src . '<br>';
        }

        // Find all links
        foreach ($html->find('a') as $element) {
            echo $element->href . '<br>';
        }
    }
}

0 个答案:

没有答案