• 下载图片 保存至本地 返回路径


    import requests
    import time
    import threading

    img_url = 'https://s3.pstatp.com/toutiao/static/img/logo.201f80d.png'
    img_dir = 'C:\Users\sas\PycharmProjects\py_win_to_unix\crontab_chk_url\personas\trunk\plugins\spider\dl_img_tmp\'

    def spider_webimg_dl_return_local_img_path(img_dir, img_url, local_default='default.DONOT_REMOVE.png'):
    r = '%s%s' % (img_dir, local_default)
    # http://tpc.googlesyndication.com/daca_images/simgad/14585742322992183828?w=400&h=209
    if '.' not in img_url:
    return r
    # http://cms-bucket.nosdn.127.net/ef46d015659f49c29bc337d081a3583f20180107130343.jpeg?imageView&thumbnail=550x0
    #https://img.alicdn.com/imgextra/i2/11236204/TB2tiTYoBNkpuFjy0FaXXbRCVXa_!!11236204.jpg
    img_url = img_url.split('?')[0]
    try:
    bytes = requests.get(img_url)._content
    if bytes != 0:
    r = '%s%s%s%s' % (
    img_dir, time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())), str(threading.get_ident()),
    img_url.replace('/', '_xl_').replace(':', '_fxl_'))
    with open(r, 'wb')as f:
    f.write(bytes)
    except Exception as e:
    print(e)
    return r


    r = spider_webimg_dl_return_local_img_path(img_dir, img_url, local_default='default.DONOT_REMOVE.png')




  • 相关阅读:
    有序数组(类模板)
    BUUCTF-Web Comment
    BUUCTF-web NiZhuanSiWei
    2020数字中国创新大赛虎符网络安全赛道-pwn count
    BUUCTF-Web Easy Calc
    xctf-web fakebook
    xctf-web supersqli
    xctf-pwn pwn200
    xctf-pwn level3
    利用updatexml()报错注入mysql
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8241528.html
Copyright © 2020-2023  润新知