写了一半的图片采集程序
只写了一半,不想再写了采的是http://dlc.pcgames.com.cn/list.jsp?dltypeid=3&taxis=0&kindid=1302&pn=25所有列表中的动漫图片
全采集了保存到服务器上,主要部分完成了,只差一些界面以及数据校验和入庫部分的程序,本来我是想把太平洋
采爆,把上面的图片全采到free.fr上,奈何free.fr狂晕,10分钟才采了2张图片。
main.php
<?php
$root=dirname(__FILE__);
$page=$_GET['page'];
if (!isset($page))
{ echo '正在初始化采集内容<br />';
$url="http://dlc.pcgames.com.cn/list.jsp?dltypeid=3&taxis=0&kindid=1302&pn=25";
$contents=file_get_contents($url);
$pattern='/<DL_herf>(.*?)<\/DL_herf>\n<DL_Name>(.*?)<\/DL_Name>\n<DL_Version>(.|\n)*?<\/DL_Counter>\n<DL_Intro><\!\\]><\/DL_Intro>/i';
preg_match_all($pattern,$contents,$out);
$cache="<?php\n \$list = array (\n";
for($i=0;$i<(count($out)-1);$i++)
{ $cache=$cache."array('url' =>'".$out[$i]."',\n";
$cache=$cache." 'title'=>'".$out[$i]."',\n";
$cache=$cache." 'intro'=>'".$out[$i]."'\n),\n\n";
}
$cache=$cache."array('url' =>'".$out[$i]."',\n";
$cache=$cache." 'title'=>'".$out[$i]."',\n";
$cache=$cache." 'intro'=>'".$out[$i]."'\n)\n\n);\n?>";
$fp=fopen("$root/data/cache.php",'wb');
fwrite($fp,$cache);
fclose($fp);
echo '初始化完成<br /><a href="main.php?page=0">开始采集图片</a><br />';
}else
{
require_once './data/cache.php';
$num=count($list);
echo '一共'.$num.'条<br />';
if ($page=='all')
echo '采集完成';
else
if ($page<$num)
{
mkdir("$root/pic/$page");
chmod ("$root/pic/$page/", 0777);
$url_forward='list.php?page='.$page.'&lid=0';
}else
{
$url_forward='main.php?page=all';
}
$message="<script>setTimeout(\"window.location.replace('$url_forward');\", 800);</script>";
echo $message;
}
?>
list.php
<?php
$page=$_GET['page'];
$lid=$_GET['lid'];
if (!isset($page)||!isset($lid))
{ echo '非法操作,退出程序';
exit;
}else
{
require_once './cai_func.php';
require_once './data/cache.php';
$url=$list[$page]['url'];
$url=str_replace('&','&',$url);
$contents=file_get_contents($url);
$pattern="/a[ .]*href *= *'(http:\/\/dlc\.pcgames\.com\.cn\/imgcounter\.jsp.*?)' *target=_blank>/i";
preg_match_all($pattern,$contents,$out);
$num=count($out);
if ($lid=='all')
{ echo '一共'.$num.'张图片,采集<br /><br />';
$connstr=file_get_contents('./data/result.txt');
echo $connstr;
unlink('./data/result.txt');
$page=$page+1;
$url_forward='main.php?page='.$page;
$message="<script>setTimeout(\"window.location.replace('$url_forward');\", 15000);</script>";
echo $message;
}
else
{
$purl=$out[$lid];
$purl=str_replace('&','&',$purl);
caipic($purl,$lid,$page);
$caistr='图片'.$purl.'采集成功<br />';
echo $caistr;
@ $fp=fopen('./data/result.txt','ab');
if(!$fp)
{echo '错误:请将pic目属的属性设置为777';
exit;
}
fwrite($fp,$caistr,strlen($caistr));
fclose($fp);
$lid=$lid+1;
if ($lid<$num)
{
$url_forward='list.php?page='.$page.'&lid='.$lid;
}else
{$lid='all';
$url_forward='list.php?page='.$page.'&lid='.$lid;
}
$message="<script>setTimeout(\"window.location.replace('$url_forward');\", 3000);</script>";
echo $message;
}
}
?>
cai_func.php
<?php
function caipic($theurl,$pg,$dir)
{
$root=dirname(__FILE__);
$contents=file_get_contents($theurl);
$pattern3='/<img src="(http:\/\/(.*?)\.pconline\.com\.cn\/games\/cartoon\/photo\/.*?)">/';
preg_match($pattern3,$contents,$quote);
$picurl=$quote;
if($quote=='www')
$picurl=str_replace('www','arch',$picurl);
$picurl=str_replace(' ','%20',$picurl);
@ $fp=fopen($picurl,'rb');
if(!$fp)
{ echo '远程文件读取失败,请检查链接或者正则表达式<br />';
}
else
{
$content='';
while (!feof($fp)) {
$content .= fread($fp, 8192);
}
fclose($fp);
}
@ $fp=fopen("$root/pic/$dir/$pg.jpg",'wb');
if (!$fp)
{ echo '图片写入失败,请检查文件夹属性';
}else
{
fwrite($fp,$content);
fclose($fp);
}
echo '图片地址'.$picurl.'<br />';
}
?>
[ 本帖最后由 winsock 于 2006-7-4 14:24 编辑 ] ;P;P;P; 要用的,自己修改下。 建立一个data和pic文件夹,属性0777 我狂晕,怎么多了那么多\\?? VBVS呢?快射精 天书!!! 不懂 +分+分~
抽抽抽~ 不明白! 强贴留名
有空学习
页:
[1]
2