首页 > php教程 > php手册 > 正文

网络爬虫脚本

php中文网
发布: 2016-06-06 20:13:34
原创
1708人浏览过

最近需要写个脚本程序抓取一些网络数据,于是就有了常见的php脚本;测试代码如下: #!/usr/local/bin/php -q?php/** * Created by PhpStorm. * User: jackqqxu * Date: 14-9-12 * Time: 上午12:34 * 解析一个目录下面的文件,分析所有的静态资源然后下载下来

最近需要写个脚本程序抓取一些网络数据,于是就有了常见的php脚本;测试代码如下:

EZIBI! 商城(原维C商城)
EZIBI! 商城(原维C商城)

前身是vitcie(维C商城),各种特性介绍: 1. 稳定、安全、高效的系统平台 EZIBI!基于PHP+MYSQL技术编写,PHP自1995发布第一个版本,经过近10年的发展,已经成为目前最流行的网络编程语言之一,其强大的数据库支持使得开发人员很轻易的就可以完成C/S架构电子商务平台的构建;MYSQL则是成熟的数据库系统。 2. 安装向导 EZIBI!提供支持多语言版的安装脚本,只需按照提

EZIBI! 商城(原维C商城) 0
查看详情 EZIBI! 商城(原维C商城)
#!/usr/local/bin/php -q
<?php
/**
 * Created by PhpStorm.
 * User: jackqqxu
 * Date: 14-9-12
 * Time: 上午12:34
 *  解析一个目录下面的文件,分析所有的静态资源然后下载下来;
 */
//echo "请输入需要提取的文件路径:\n";
//$path = fread(STDIN, 100);
//echo "程序即将读取 $path 路径下面的文件\n";
//echo "请输入需要提取的文件类型:\n";
//$type = fread(STDIN, 100);
// Open a known directory, and proceed to read its contents
//$path = '/Users/jackqqxu/Desktop/task/game/a_grain_of_truth_files/css/';
$destPath = '/Users/jackqqxu/task/aliyunsvn/health/grain/views/locations/'; //静态文件html
$sourcePath = '/Users/jackqqxu/task/aliyunsvn/health/grain/js/'; //静态文件html
//$baseUrl = 'http://www.zamolski.com/agot/resources/stylesheets/';
$netSourceUrl = 'http://www.zamolski.com/agot/views/locations/'; //现在获取位置信息
//$type = '.css';
$type = '.js';  //很多需要获取定位的位置信息;
$typeLen = strlen($type);
//echo 'r=' . realpath('/Users/jackqqxu/Desktop/task/game/a_grain_of_truth_files/css/../images/ui/frame_h.png') . "\n\n";
//echo "the programe will read the $type from the $path\n";
//if (!is_dir($destPath)) {
//    exec('mkdir -p ' . $destPath);
//}
    if ($dh = opendir($sourcePath)) {
        while (($file = readdir($dh)) !== false) {
            $fileType = filetype($sourcePath . $file);
            if ($fileType != 'file') {
                continue;
            }
//            echo 'f=' . $file . substr($file, strlen($file)-$typeLen) . "\n";
            if (substr($file, strlen($file)-$typeLen) == $type) {   //类型相同
//                echo "filename: $file : filetype: " . filetype($path . $file) . "\n";
                echo '$sourcePath . $file=' . $sourcePath . $file . "\n";
                $fileContentArr = file($sourcePath . $file);
                foreach($fileContentArr as $fileLine) {
//                    if ($fileLine =~ /url\((.*?)\)/){
//                    if (preg_match_all("/url\((.*?)\)/", $fileLine, $matches))  {   //css中通过url获取其他图片;
                    if (preg_match_all("/gotoLocation\(\"(.*?)\"\)/", $fileLine, $matches))  {   //中通过关键词获取其他文件;
//                        print_r($matches);exit;
//                        foreach($matches[1] as $matchImgUrl) {
                        foreach($matches[1] as $matchUrl) {
                            $sourceUrl = $netSourceUrl . $matchUrl . '.html';
                            echo 'n='.$sourceUrl."\n";//exit;
                            $descFile = $destPath . $matchUrl . '.html';
//                            echo 'fs=' . function_exists('realpath');
//                            echo 'ni=' . $newImgFile."\n";//exit;
//                            echo 'mkdir -p=' . dirname($newImgFile);
//                            exec('mkdir -p ' . dirname($newImgFile));
                            $ret = file_put_contents($descFile, file_get_contents($sourceUrl));
                            if ($ret) {
                                echo "文件$descFile 写入成功\n";
//                                exit;
                            }
//                            exit;
                        }
                    }
                }
            }
        }
        closedir($dh);
    }
?>
登录后复制


codingless|网络爬虫脚本 Tags:  

Del.icio.us
@@##@@
Facebook
@@##@@
TweetThis
@@##@@
Digg
@@##@@
StumbleUpon
@@##@@

Comments:  0 (Zero), Be the first to leave a reply!


You might be interested in this:  

  • codingless|网络爬虫脚本  Ubuntu 安装JRE7的快捷方法(验证有效)
  • codingless|网络爬虫脚本  BigPipe的技术实现【转】
  • codingless|网络爬虫脚本  'insertCell' called on an object that does not implement interface HTMLTableRowElement.
  • codingless|网络爬虫脚本  javascript性能优化-repaint和reflow
  • codingless|网络爬虫脚本  Fiddler工作原理

Copyright © web代码网 [网络爬虫脚本], All Right Reserved. 2014.
codingless|网络爬虫脚本codingless|网络爬虫脚本codingless|网络爬虫脚本codingless|网络爬虫脚本codingless|网络爬虫脚本
相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号