1 |
wget -mk -w 10 http://cwgl.xzit.edu.cn/ |
-w 10代表间隔10秒下载一个文件,避免频繁访问网站引起不必要的误会。
可以用-A参数指定UA -k表示替换绝对路径为相对路径
下载回来以后 把所有asp文件(非文件夹,文件夹用-type d)重命名为html,
[[......]
1 |
wget -mk -w 10 http://cwgl.xzit.edu.cn/ |
-w 10代表间隔10秒下载一个文件,避免频繁访问网站引起不必要的误会。
可以用-A参数指定UA -k表示替换绝对路径为相对路径
下载回来以后 把所有asp文件(非文件夹,文件夹用-type d)重命名为html,
[[......]
php的exec的参数里面如果有空格会导致执行失败,用escapeshellarg()即可(实际上是加了引号)
下面这里例子是使用php遍历pdf并且转化为txt的例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php /* * 递归获取指定路径下的所有文件或匹配指定正则的文件(不包括“.”和“..”),结果以数组形式返回 * @param string $dir * @param string [$pattern] * @return array */ function file_list($dir,$pattern="") { $arr=array(); $dir_handle=opendir($dir); if($dir_handle) { // 这里必须严格比较,因为返回的文件名可能是“0” while(($file=readdir($dir_handle))!==false) { if($file==='.' || $file==='..') { continue; } $tmp=realpath($dir.'/'.$file); if(is_dir($tmp)) { $retArr=file_list($tmp,$pattern); if(!empty($retArr)) { $arr[]=$retArr; } } else { if($pattern==="" || preg_match($pattern,$tmp)) { $arr[]=$tmp; } } } closedir($dir_handle); } return $arr; } function convert($list){ print 'fucking:'.$list.'<br />'; $dest=substr($list,0,count($list)-5); $list=escapeshellarg($list); $dest=escapeshellarg($dest); #print $list.$dest; exec("pdftotext -enc UTF-8 $list $dest.txt",$out); print '<br />'.'done'.'<br />'; return $out; } function de_array($array){ static $result_array=array(); foreach($array as $value) { if(is_array($value)) { de_array($value); } else $result_array[]=$value; } return $result_array; } set_time_limit(0); $lists=file_list(getcwd().'\pdf',"/\.pdf$/i"); $lists=de_array($lists); #print_r($lists); foreach ($lists as $key=>$list){ convert($list); } ?> |
尤其是这个函数de_array(),使用递归来把多[......]
[......]