<?php
header("Content-type: text/html; charset=gb2312");
set_time_limit(0);
include 'conn.php';
getInfo('557494596-431972218');
function getInfo($a = '' )
{
if( !empty($a) )
{
for( $i = 1 ; $i <= 10 ; $i++)
{
$html = file_get_contents("http://www.aibang.com/?area=biz&cmd=dimg&id=".$a."&n=$i");
$match = '/<div class=\"div800\">(.*?)<\/div>\s+([^<]*?)\s*</si';
preg_match($match,$html,$arr);
$res = array_filter($arr);
if(empty($res))
echo "没有找到合适的网页, url:"."http://www.aibang.com/?area=biz&cmd=dimg&id=".$a."&n=$i";
//print_r( html_entity_decode($arr[1]) . "=================" . $arr[2] );
$image = html_entity_decode($arr[1]);
$name = $arr[2];
}?>
图片已经采集到了 ,怎么保存到本地呀,求大家给完善一下!!
header("Content-type: text/html; charset=gb2312");
set_time_limit(0);
include 'conn.php';
getInfo('557494596-431972218');
function getInfo($a = '' )
{
if( !empty($a) )
{
for( $i = 1 ; $i <= 10 ; $i++)
{
$html = file_get_contents("http://www.aibang.com/?area=biz&cmd=dimg&id=".$a."&n=$i");
$match = '/<div class=\"div800\">(.*?)<\/div>\s+([^<]*?)\s*</si';
preg_match($match,$html,$arr);
$res = array_filter($arr);
if(empty($res))
echo "没有找到合适的网页, url:"."http://www.aibang.com/?area=biz&cmd=dimg&id=".$a."&n=$i";
//print_r( html_entity_decode($arr[1]) . "=================" . $arr[2] );
$image = html_entity_decode($arr[1]);
$name = $arr[2];
}?>
图片已经采集到了 ,怎么保存到本地呀,求大家给完善一下!!
解决方案 »
- 请求一个采集程序代码 欢迎加入围观
- php正则问题
- 咨询phpmyadmin中文编码中文乱码问题
- PHP怎样使用文本框的全选..............................
- preg_match使用问题
- 用imagecreatefromjpeg创建图像时失败,提示is not a valid jpeg file, 但我检查了传入imagecreatefromjpeg的参数是正确的jpeg的文件啊
- 字符串比较函数调用出错,补救!
- 国内外有哪些博客系统做的比较不错的??^_^多讨论讨论
- 图片上传的问题?
- php 中如何得到mssql存储过程得返回值?查了资料,没找到答案.
- PHP留言板基础性问题
- php curl模拟提交
接着 采集出图片的地址:
preg_match('/src="(.*?)"/is',$arr[1],$match)
//显示采集的图片:
echo "<img src=".$match[1].">";
//保存到本地:需建立img文件夹
$path = 'img';
if(file_put_contents($path . basename($picurl), file_get_contents($picurl))){
echo "成功下载到img文件夹中";
}else{
echo "下载失败";
}
preg_match($match,$html,$arr);
接着 采集出图片的地址:
preg_match('/src="(.*?)"/is',$arr[1],$match)
//显示采集的图片:
echo "<img src=".$match[1].">";
//保存到本地:需建立img文件夹
$path = 'img';
if(file_put_contents($path . basename($match[1]), file_get_contents($match[1]))){
echo "成功下载到img文件夹中";
}else{
echo "下载失败";
}
语法错误 echo "<img src=".$match[1].">";
这一句 少了个分号
加上就好
请把它加入到你的函数中即可。 //获取图片地址
preg_match('/src="(.*?)"/is',$arr[1],$match);
$imgurl = $match[1];
echo "<img src=".$match[1].">";
//获取图片名称
preg_match('/href="(.*?)"/is',$arr[1],$imgext);
$ext = basename($imgext[1]);
//echo $ext ;
//保存到本地
if(file_put_contents($ext, file_get_contents($imgurl))){
echo "成功下载";
}else{
echo "下载失败";
}
一 最好不要for循环。一般都是一个一个的抓,抓完一个再跳转本页抓下一个。二 人家图片共有多少个在页面上是有显示的,先抓这个,然后根据这个确定循环抓图的次数,这样可以一个不漏的把所有相关图抓下来