我们来写一个爬虫程序,公司之前做过电影网的APP,抓取时光网的信息。下面的程序会完成这个功能,不过功能比较简单,用户可以查看最近有什么电影在上映。
先介绍下开发环境:winxp, xampp, speedPHP;
扩展模块:simple_html_dom.php; chrome viewjson;
1、在你抓取网页调试的时候,很有可能会出现如下错误提示:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 74500 bytes) in ...
在speedphp config.php 中加入以下代码:
// 设置内存占用量
@ini_set('memory_limit','1024M');</span>
2、在抓取图片的时候遇到json格式的数组
我们这里采用正则匹配
preg_match_all("/\"要匹配的头部\":\"(.*?)\",/is", $search_array, $return_array);
3、在做缓存的时候,可能回调出现以下错误:
Fatal error: Maximum execution time of 60 seconds exceeded in ..
我来给大家翻译下:延迟时间超出60S,程序报错。既然是延迟设置除了问题,我们在php.ini中找到‘max_execution_time’ 设置为 ‘600’,重启Apache。
4 放假在家,没有WINDOWS开发环境,只能用LINUX做了:
遇到了各种问题,一时半会儿也说不完,新家了压缩图片的功能,没有做过数据库.讲究用吧.
遗留问题:
1、引用文件路径的问题
<span style="white-space:pre"> </span>/* 这里在myController中定义了extensions_path, 出了问题,页面显示
<span style="white-space:pre"> </span>Fatal error: require_once() [function.require]: Failed opening required...include_path='.;\xampp\php\pear\') in*/
//require_once($strhis->extensions_path . 'simple_html_dom.php');
/* 这个为正确配置,即跟caiji.php在同级目录下 */
require_once('simple_html_dom.php');
源码下载:click me