def http_down_p(urls):
for url in urls:
http_down(url)
def main(url):
#pics = analysepic.analyse_pic("http://discovery.163.com/photoview/4T8F0001/39413.html?from=tj_xgtj#p=9C6GI6EJ4T8F0001")
urls = analyseurl.analyse_url(url)
print "%d url found!" %(len(urls))
all_pics=[]
i=0
for u in urls:
i+=1
pics = analysepic.analyse_pic(u)
print "[%3d]%d pics found in '%s'" %(i,len(pics),u)
for pic in pics:
if not pic in all_pics:
all_pics.append(pic)
print "total pics %d" %(len(all_pics))
http_down_p(all_pics)
if __name__=='__main__':
if(len(sys.argv)<2):
print "Usage: httpdown.py url"
else:
main(sys.argv[1])
analyseurl.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2,re,string,sys
from time import sleep
import md5
import json
sufixs=['.html','htm']
def analyse_url(url):
pic_urls=[]
try:
http_file = urllib2.urlopen(url)
lines = http_file.readlines()
for line in lines:
new_line = string.lower(line)
begin = new_line.find("http://")
if(begin>0):
end_index=new_line.find("\"",begin)
end_str = ''
end=-1
for suf in sufixs:
end = new_line.find(suf,begin,end_index)
if(end>0):
end_str=suf
break;
end =end+len(end_str)
if(begin>0 and end>0 and begin<end):
pic_url=line[begin:end]
pic_urls.append(pic_url)
http_file.close()
except Exception,e:
print 'error: ',e
return pic_urls
if __name__=='__main__':
if(len(sys.argv)<2):
print "Usage: analyseurl.py url"
else:
result = analyse_url(sys.argv[1])
for item in result:
print item
analysepic.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2,re,string,sys
from time import sleep
import md5
import json
sufixs=['.jpg','jpeg','.png','.gif','.bmp']
def get_one_pic(l):
new_line = string.lower(l)
index = -1
end_str = ''
for suf in sufixs:
index = new_line.find(suf)
if(index>0):
end_str=suf
break;
if(index>0):
begin=l.rfind("http:",l.rfind("\"",0,index),index)
end =index+len(end_str)
if(begin>0 and end>0 and begin<end):
pic=l[begin:end]
return (pic, end)
return ("",-1)
def analyse_pic(url):
pic_urls=[]
try:
http_file = urllib2.urlopen(url)
lines = http_file.readlines()
for line in lines:
pic_url,end_index=get_one_pic(line)
while(len(pic_url)>0):
pic_urls.append(pic_url)
print pic_url
line=line[end_index:]
pic_url,end_index=get_one_pic(line)
http_file.close()
except Exception,e:
print 'error: ',e
return pic_urls
if __name__=='__main__':
if(len(sys.argv)<2):
print "Usage: analysepic.py url"
else:
result = analyse_pic(sys.argv[1])
for item in result:
print item