首页 > 解决方案 > 无法浏览谷歌云上的图书馆

问题描述

我想使用 lravel 的“Goutte”进行抓取,它在本地环境中成功,但在 Google Cloud 环境中出现错误。可能没有在控制器的“使用”部分中引用。

错误图片在这里

我参考了这个网站来了解如何使用“Goutte”。

使用的控制器如下

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
// Probably not able to refer to this ---------|
use Weidner\Goutte\GoutteFacade as GoutteFacade;

class BookController extends Controller
{
    public function index(){

        $goutte = GoutteFacade::request('GET', 'https://www.amazon.co.jp/gp/bestsellers/electronics/3946818051?ref_=Oct_BSellerC_3946818051_SAll&pf_rd_p=7019a35e-d4ad-5da4-8fdd-f9f5c8ef9428&pf_rd_s=merchandised-search-10&pf_rd_t=101&pf_rd_i=3946818051&pf_rd_m=AN1VRQENFRJN5&pf_rd_r=61C7KYXHQFEAY80RGM67&pf_rd_r=61C7KYXHQFEAY80RGM67&pf_rd_p=7019a35e-d4ad-5da4-8fdd-f9f5c8ef9428');

        $images = [];
        $texts = [];

        $goutte->filter('.a-dynamic-image')->each(function ($node) use (&$images) {
            $images[] = $node->attr('src');
        });

        $goutte->filter('.p13n-sc-truncate')->each(function ($node) use (&$texts) {
            $texts[] = $node->text();
        });

        $params = [
            'images' => $images,
            'texts' => $texts,
        ];

        return view('book.index',$params);
    }
}

作曲家.json

"require": {
        // add
        "fabpot/goutte": "^3.3.0",
        "weidner/goutte": "^1.6"
    },

配置/app.php

'providers' => [
           // add
           Weidner\Goutte\GoutteServiceProvider::class, 
]

'aliases' => [
        // add
        'Goutte' => Weidner\Goutte\GoutteFacade::class,
]

Postscript
@Hamelraj
此图像与云作曲家更新一致吗?
此外,即使我再次部署该错误也不会改善。识别“gcloud app deploy”在本地再次执行是否正确?

标签: phpgoogle-app-enginegoogle-cloud-platform

解决方案


推荐阅读