搜尋
首頁php教程php手册网络爬虫脚本

网络爬虫脚本

Jun 06, 2016 pm 08:13 PM
抓取爬蟲程式網路腳本需要

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

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

#!/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
codingless|网络爬虫脚本
Facebook
codingless|网络爬虫脚本
TweetThis
codingless|网络爬虫脚本
Digg
codingless|网络爬虫脚本
StumbleUpon
codingless|网络爬虫脚本

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.
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具