近来在看python教程…晚上想把一个网站上到demo下载下来。偷懒用perl写了个脚本。
查看code文件 用sed来匹配出url到方法还没想到。。
好像用wget -r到话倒是可以实现把这些文件下到本地,但是好像把整站都下下来了。
说实话,perl好久没用了…
#!/usr/bin/perl use strict; use warnings; my $index = ‘www.greenteapress.com/thinkpython/code‘; my $getPage = `wget $index`; $getPage; sub wget_urls($){ my $file = ‘code‘; my ($url,$filename,$cmd) = @_; open(F,$file) or die ("$!"); while(<F>) { if ($_ =~ m/\<a href=\"(\w+\.py)\">\w+\.*/) { $url = $1; $filename = $index . "/" . $url; $cmd = `wget $filename`; $cmd; } } close(F); } &wget_urls
本文出自 “愤怒的虚拟机” 博客,请务必保留此出处http://fengxs.blog.51cto.com/2963781/1394767
原文:http://fengxs.blog.51cto.com/2963781/1394767