爬斗图啦 - 在线代码运行


            
执行结果

名称:爬斗图啦

当前代码

import requests as r[/align]
import urllib
import re
import os
script_path = os.path.realpath(__file__)
script_dir = os.path.dirname(script_path)
def getapage(url):
    headers = {
        "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"}
    html = r.get(url, headers=headers).text
    regex = """<img src="//static.doutula.com/img/loader.gif" style="width: 100%; height: 100%;" data-original="(.*?)" alt="(.*?)" class="img-responsive lazy image_dta" data-backup"""
    resulit = re.findall(regex, html)
    return resulit
if not os.path.exists(script_dir + '/imgs'):
    os.mkdir(script_dir + '/imgs')
for i in range(1,1959+1):
    resulit=getapage("http://www.doutula.com/photo/list/?page="+str(i))
    print("正在获取第"+str(i)+"页")
    for imgs in resulit:
        o = open(script_dir + "/imgs/" + imgs[1] + ".gif", "wb")
        img = urllib.request.urlopen(imgs[0])
        o.write(img.read())
        o.close()