找回密码
 注册
广告投放 虚位以待【阿里云】2核2G云新老同享 99元/年,续费同价做网站就用糖果主机-sugarhosts.comJtti.com-新加坡服务器,美国服务器,香港服务器
查看: 789|回复: 16

写了一半的图片采集程序

[复制链接]
发表于 2006 年 7 月 4 日 14:02:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
只写了一半,不想再写了

采的是http://dlc.pcgames.com.cn/list.jsp?dltypeid=3&taxis=0&kindid=1302&pn=25所有列表中的动漫图片
全采集了保存到服务器上,主要部分完成了,只差一些界面以及数据校验和入庫部分的程序,本来我是想把太平洋
采爆,把上面的图片全采到free.fr上,奈何free.fr狂晕,10分钟才采了2张图片。

main.php


  1. <?php

  2. $root=dirname(__FILE__);
  3. $page=$_GET['page'];

  4. if (!isset($page))
  5. { echo '正在初始化采集内容<br />';
  6.          $url="http://dlc.pcgames.com.cn/list.jsp?dltypeid=3&taxis=0&kindid=1302&pn=25";
  7.          $contents=file_get_contents($url);
  8.    $pattern='/<DL_herf>(.*?)<\/DL_herf>\n<DL_Name>(.*?)<\/DL_Name>\n<DL_Version>(.|\n)*?<\/DL_Counter>\n<DL_Intro><\!\[CDATA\[(.*?)\]\]><\/DL_Intro>/i';
  9.    preg_match_all($pattern,$contents,$out);
  10.    $cache="<?php\n \$list = array (\n";
  11.    for($i=0;$i<(count($out[1])-1);$i++)
  12.     { $cache=$cache."  array('url' =>'".$out[1][$i]."',\n";
  13.             $cache=$cache."        'title'=>'".$out[2][$i]."',\n";
  14.             $cache=$cache."        'intro'=>'".$out[4][$i]."'\n),\n\n";        
  15.     }
  16.    $cache=$cache."  array('url' =>'".$out[1][$i]."',\n";
  17.    $cache=$cache."        'title'=>'".$out[2][$i]."',\n";
  18.    $cache=$cache."        'intro'=>'".$out[4][$i]."'\n)\n\n);\n?>";

  19.    $fp=fopen("$root/data/cache.php",'wb');
  20.    fwrite($fp,$cache);
  21.    fclose($fp);
  22.    echo '初始化完成<br /><a href="main.php?page=0">开始采集图片</a><br />';
  23. }else
  24.   {
  25.     require_once './data/cache.php';
  26.     $num=count($list);
  27.     echo '一共'.$num.'条<br />';
  28.     if ($page=='all')
  29.       echo '采集完成';
  30.      else
  31.        if ($page<$num)
  32.         {
  33.                  mkdir("$root/pic/$page");
  34.                  chmod ("$root/pic/$page/", 0777);
  35.            $url_forward='list.php?page='.$page.'&lid=0';
  36.         }else
  37.         {  
  38.                  $url_forward='main.php?page=all';
  39.          }
  40.       $message="<script>setTimeout("window.location.replace('$url_forward');", 800);</script>";
  41.       echo $message;

  42.   }



  43. ?>
复制代码


list.php

  1. <?php
  2. $page=$_GET['page'];
  3. $lid=$_GET['lid'];

  4. if (!isset($page)||!isset($lid))
  5. { echo '非法操作,退出程序';
  6.          exit;
  7. }else
  8. {
  9.   require_once './cai_func.php';
  10.   require_once './data/cache.php';
  11.   $url=$list[$page]['url'];
  12.   $url=str_replace('&','&',$url);
  13.   $contents=file_get_contents($url);
  14.   $pattern="/a[ .]*href *= *'(http:\/\/dlc\.pcgames\.com\.cn\/imgcounter\.jsp.*?)' *target=_blank>/i";
  15.   preg_match_all($pattern,$contents,$out);
  16.   $num=count($out[1]);
  17.   
  18.    if ($lid=='all')
  19.     { echo '一共'.$num.'张图片,采集<br /><br />';
  20.             $connstr=file_get_contents('./data/result.txt');
  21.             echo $connstr;
  22.             unlink('./data/result.txt');
  23.             $page=$page+1;
  24.             $url_forward='main.php?page='.$page;
  25.             $message="<script>setTimeout("window.location.replace('$url_forward');", 15000);</script>";
  26.       echo $message;
  27.     }
  28.    else
  29.     {
  30.             $purl=$out[1][$lid];
  31.             $purl=str_replace('&','&',$purl);
  32.             caipic($purl,$lid,$page);
  33.             $caistr='图片'.$purl.'采集成功<br />';
  34.       echo $caistr;
  35.       @ $fp=fopen('./data/result.txt','ab');
  36.       if(!$fp)
  37.        {echo '错误:请将pic目属的属性设置为777';
  38.         exit;
  39.       }
  40.       fwrite($fp,$caistr,strlen($caistr));
  41.       fclose($fp);
  42.       $lid=$lid+1;
  43.       if ($lid<$num)
  44.         {
  45.            $url_forward='list.php?page='.$page.'&lid='.$lid;
  46.         }else
  47.         {  $lid='all';
  48.                  $url_forward='list.php?page='.$page.'&lid='.$lid;
  49.          }
  50.       $message="<script>setTimeout("window.location.replace('$url_forward');", 3000);</script>";
  51.       echo $message;
  52.    }
  53. }

  54. ?>
复制代码


cai_func.php

  1. <?php
  2. function caipic($theurl,$pg,$dir)
  3. {
  4. $root=dirname(__FILE__);
  5. $contents=file_get_contents($theurl);


  6. $pattern3='/<img src="(http:\/\/(.*?)\.pconline\.com\.cn\/games\/cartoon\/photo\/.*?)">/';
  7. preg_match($pattern3,$contents,$quote);
  8. $picurl=$quote[1];

  9. if($quote[2]=='www')
  10.   $picurl=str_replace('www','arch',$picurl);

  11. $picurl=str_replace(' ','%20',$picurl);
  12. @ $fp=fopen($picurl,'rb');
  13. if(!$fp)
  14.   { echo '远程文件读取失败,请检查链接或者正则表达式<br />';
  15.   }
  16.   else
  17.   {
  18.     $content='';
  19.     while (!feof($fp)) {
  20.        $content .= fread($fp, 8192);
  21.       }
  22.       
  23.   fclose($fp);  
  24.   }

  25. @ $fp=fopen("$root/pic/$dir/$pg.jpg",'wb');
  26.   if (!$fp)
  27.     { echo '图片写入失败,请检查文件夹属性';
  28.     }else
  29.      {
  30.       fwrite($fp,$content);
  31.       
  32.       fclose($fp);
  33.      }

  34. echo '图片地址'.$picurl.'<br />';
  35. }



  36. ?>
复制代码

[ 本帖最后由 winsock 于 2006-7-4 14:24 编辑 ]
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2006 年 7 月 4 日 14:03:21 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
;
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2006 年 7 月 4 日 14:03:39 | 显示全部楼层
要用的,自己修改下。 建立一个data和pic文件夹,属性0777
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2006 年 7 月 4 日 14:05:03 | 显示全部楼层
我狂晕,怎么多了那么多\\??
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 14:05:35 | 显示全部楼层
VBVS呢?快射精
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 14:08:57 | 显示全部楼层
天书!!!
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 14:13:03 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
不懂
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 14:18:54 | 显示全部楼层
+分+分~
抽抽抽~
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 14:39:25 | 显示全部楼层
不明白!
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2006 年 7 月 4 日 20:03:10 | 显示全部楼层
强贴留名

有空学习
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2025 年 2 月 5 日 06:51 , Processed in 0.032376 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表