<?
$p="http://news.cnhubei.com/hbrb/hbrbsglk/hbrb01/200905/W020090504254969587296.jpg";
$t_url ="http://news.cnhubei.com/hbrb/hbrbsglk/hbrb01/200905/t662541.shtml";
$rs = file_get_pic($p);
echo $rs;
function file_get_pic($str) {
global $url_domin,$t_url;
$ch = curl_init();
//echo " <BR>".$from_url;
curl_setopt($ch, CURLOPT_URL, $str);
curl_setopt($ch, CURLOPT_HEADER, 0); //返回内容中包含 HTTP 头
//curl_setopt($ch,CURLOPT_POST,1);
$useragent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; QQDownload 1.7; TencentTraveler 4.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER, $t_url);
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
//curl_setopt($ch,CURLOPT_COOKIE,"hiido_lv=1241423490703&hiido_ti=1241425695046&hiido_tod=4&hiido_ui=0.14425078706025363");
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
//echo $t_url;
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
?>
curl 抓取图片(PHP)
最新推荐文章于 2021-03-11 18:49:22 发布
本文提供了一个使用PHP通过cURL抓取网络图片的示例代码。该示例展示了如何设置cURL选项来请求特定URL上的图片资源,并将其内容输出或保存到本地文件。文中还介绍了如何配置User-Agent和Referer等头部信息。
3789

被折叠的 条评论
为什么被折叠?



