码迷,mamicode.com
首页 > 其他好文 > 详细

将乌云漏洞图片下载到本地

时间:2016-10-27 13:27:42      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:exce   port   cal   efi   try   return   pre   sql   led   

#coding=utf-8
import MySQLdb
import re
import requests

conn = MySQLdb.connect(host=‘127.0.0.1‘,user=‘root‘,passwd=‘123456‘,db=‘wooyunbugs‘,charset=‘utf8‘)
cursor = conn.cursor()

def q():
    sql = ‘select * from `a`‘
    cursor.execute(sql)
    for row in cursor.fetchall():
        id = int(row[0])
        print id,
        content1 = row[2]
        filenameList = f(content1)
        if len(filenameList)== 0:
            pass
        else:
            for imgUrl in filenameList:
                try:
                    downloadImageFile(imgUrl)
                    print ‘success‘
                except:
                    pass        

def f(c):
    re1 = re.compile(‘<img src="(http:\/\/static.wooyun.org\/wooyun\/.*?)"‘)
    s = re1.findall(c)
    return s


def downloadImageFile(imgUrl):  
    local_filename = imgUrl.split(‘/‘)[-1]
    local_filedir = imgUrl.split(‘/‘)[-2]  
    print "Download Image File=", local_filename  
    r = requests.get(imgUrl, stream=True, timeout=20)
    dirName =local_filedir
    import os
    if not os.path.exists(dirName):
        os.makedirs(dirName)
    with open(dirName+‘/‘+local_filename, ‘wb‘) as f:  
        for chunk in r.iter_content(chunk_size=1024):  
            if chunk: 
                f.write(chunk)  
                f.flush()  
        f.close()
             
if __name__ == ‘__main__‘:
    q()

  

将乌云漏洞图片下载到本地

标签:exce   port   cal   efi   try   return   pre   sql   led   

原文地址:http://www.cnblogs.com/depycode/p/6003441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!