保存网页图片

import requests, re, winsound
from PIL import Image

r = requests.get('略略略photo/241530/')
jpg_list = jpg_list = re.findall('data-original="(https.*?media.*?jpg.*?\d{10})', r.text)

jiemi=1
def comic_jiemi(fp):
#某漫画网站把图片分割乱序。
    image = Image.open(fp=fp)
    w, h = image.size
    box1 = (0, 0, w, int(h / 10))
    box2 = (0, int(h / 10), w, int(h / 10) * 2)
    box3 = (0, int(h / 10) * 2, w, int(h / 10) * 3)
    box4 = (0, int(h / 10) * 3, w, int(h / 10) * 4)
    box5 = (0, int(h / 10) * 4, w, int(h / 10) * 5)
    box6 = (0, int(h / 10) * 5, w, int(h / 10) * 6)
    box7 = (0, int(h / 10) * 6, w, int(h / 10) * 7)
    box8 = (0, int(h / 10) * 7, w, int(h / 10) * 8)
    box9 = (0, int(h / 10) * 8, w, int(h / 10) * 9)
    box10 = (0, int(h / 10) * 9, w, int(h / 10) * 10)

    im1 = image.crop(box1)
    im2 = image.crop(box2)
    im3 = image.crop(box3)
    im4 = image.crop(box4)
    im5 = image.crop(box5)
    im6 = image.crop(box6)
    im7 = image.crop(box7)
    im8 = image.crop(box8)
    im9 = image.crop(box9)
    im10 = image.crop(box10)

    flag = Image.new('RGB', (w, h))
    flag.paste(im1, (0, 9 * int(h / 10)))
    flag.paste(im2, (0, 8 * int(h / 10)))
    flag.paste(im3, (0, 7 * int(h / 10)))
    flag.paste(im4, (0, 6 * int(h / 10)))
    flag.paste(im5, (0, 5 * int(h / 10)))
    flag.paste(im6, (0, 4 * int(h / 10)))
    flag.paste(im7, (0, 3 * int(h / 10)))
    flag.paste(im8, (0, 2 * int(h / 10)))
    flag.paste(im9, (0, 1 * int(h / 10)))
    flag.paste(im10, (0, 0))
    #fp = 'C:\\Users\\Administrator\\Desktop\\3\\'+name
    flag.save(fp=fp)
    image.close()


session = requests.session()
# session 肉眼可见的快,比对直接r2 = requests.get()



for i in jpg_list:
    print(i)
    r2 = session.get(i)
    print(r2.status_code)
    name = i.split('/')[-1].split('?')[0]
    with open('F:\\18comic\\3d+cn\\3\\' + name, 'wb')as f:
        f.write(r2.content)
        print(len(r2.content))
    fp = 'F:\\18comic\\3d+cn\\3\\' + name
    if jiemi:
        comic_jiemi(fp)
winsound.Beep(600, 1000)



    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容