Python练习----download
这个是我最近学Python做的小脚本
#!/usr/bin/python import subprocess import re import os url_=input('please input your url:') url_1='http://%s' %url_ cmd='wget %s' %url_1 subprocess.call(cmd,shell=True) if re.search('\/[^/]+',url_) is None: filename='index.html' else: res=re.search('\/[^/]+',url_).group() filename=re.search('\w+',res).group() subprocess.call('touch /download/url_in_web.txt',shell=True) f2=open('url_in_web.txt','w+',encoding='utf-8') with open(filename,'r',encoding='utf-8') as f: for line in f: if re.search('\"[^""]+\"',line) is None: continue else: new_line=re.search('\"[^""]+\"',line,flags=0).group() f2.writelines(new_line+'\n') f2.close() with open('url_in_web.txt','r',encoding='utf-8') as f3: for line_1 in f3: if re.search('^\"\w+',line_1) is None: continue else: line_2=re.search('[^""]+',line_1).group() cmd_5='wget %s' %(url_1+'/'+line_2) print(cmd_5) subprocess.call(cmd_5,shell=True)
Nothing is true,Nothing is fake.