Ejemplo n.º 1
0
def down_pic(url, save_path):
    logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                  "正在下载 %s" % url)
    print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "正在下载 %s" % url)
    pic_name = url[str(url).rfind("/") + 1:]
    # logging.error(pic_name)
    pic_full_name = save_path + '/' + pic_name
    try:
        urllib.request.install_opener(opener)
        urllib.request.urlretrieve(url, pic_full_name)
        if download_only_color_images:
            logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                          " 判断是否是彩色图片...")
            print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                  " 判断是否是彩色图片...")
            colors = ColorUtil.get_color_structure(pic_full_name)
            if len(colors) < min_colors_count:
                logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                              " 非彩色图片,删除该图片...")
                print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      " 非彩色图片,删除该图片...")
                os.remove(pic_full_name)
        return "成功"
    except Exception as e:
        logging.error(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " " +
                      str(e))
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " " + str(e))
        logging.error(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " 下载漫画出错")
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " 下载漫画出错")
        return e