- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys,os,re
- DIR_TARGET="/home/ray/图片/down"
- reg=re.compile("((?<=imgurl=)http.*?\\.(jpg|gif|png|bmp|jpeg))")#正则表达式匹配下载地址
- fd=file(sys.argv[1],'r')
- html=fd.read()
- fd.close()
- results=reg.findall(html)
- if results:
- os.chdir(DIR_TARGET)
- for one in results:
- dlcommand="wget -Nnv %s" %(one[0])
- if os.system(dlcommand)==0:
- print "Download %s ..." %(one[0])
- else:
- print "Fail download %s ..." %(one[0])
- print "done"
- else:
- print "empty results"
- #该片段来自于http://www.codesnippet.cn/detail/100420132803.html
来源: http://www.codesnippet.cn/detail/100420132803.html