【问题标题】:how to download image in Goutte如何在 Goutte 中下载图像
【发布时间】:2015-08-07 16:37:16
【问题描述】:

我想下载此page 中的图像。图片来源为http://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg。我尝试使用这个下载它:

$client = new Goutte\Client ();
$client->getClient->get($img_url, array('save_to' => $img_url_save_name));

但是我失败了,然后我意识到如果我直接访问http://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg,我会被CDN nginx服务器拒绝。我必须在“www.pixv.net”页面访问此图片链接,这意味着我的图片请求参考是“www.pixv.net”。如何在 Goutte 中做到这一点?

【问题讨论】:

    标签: php web-crawler guzzle goutte


    【解决方案1】:

    我得到了答案:

            $client->getClient()->get($img_url, ['save_to' => $img_url_save_name,
                'headers'=>['Referer'=>$src]
                ]);
    

    实际上我可以在Goutte\Client 中设置标头Referer,但是没有选项可以提供保存图像的路径。所以我最终改用 Guzzle Client。

    【讨论】:

    猜你喜欢
    • 2014-07-29
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多