dqd82461 2017-01-13 15:51 采纳率: 0%
浏览 49

如何使用curl从站点获取图像

How do I get images from a specific site inside html content?

See the example here .

Here http://www.techtunes.com.bd/android-apps/tune-id/214272 is the main post link. I'm scraping content inside div#content using php. But images in the post give 403.

How do I show that image? I'm using the Goutte Library

  • 写回答

1条回答 默认 最新

  • douxia6554 2017-01-13 15:53
    关注

    use it like this: call the function with $url the image path, and $filename the image stored path.

    private function httpgetfile($url, $filename)
    {
        $fp = fopen($filename, 'a+');
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
        return;
    }
    
    评论

报告相同问题?