首页 > 技术文章 > 爬取斗图

randysun 2019-07-23 15:14 原文

一、 爬取斗图

import re
import requests
"""
@author RansySun
@create 2019-07-22-17:18
"""
for i in range(1, 16):
    response = requests.get(f'https://www.doutula.com/photo/list/?page={i}')
    data = response.text

    """
    <img referrerpolicy="no-referrer" src="http://ww2.sinaimg.cn/bmiddle/9150e4e5gy1g58b6qkhgzj2095095t8x.jpg" style="width: 100%; height: 196px;" data-original="http://ww2.sinaimg.cn/bmiddle/9150e4e5gy1g58b6qkhgzj2095095t8x.jpg" alt="滚呐" class="img-responsive lazy image_dta loaded" data-backup="http://img.doutula.com/production/uploads/image/2019/07/22/20190722785359_osqLXz.jpg" data-was-processed="true">
    
    """
    img_res = re.findall('data-original="(.*?)"', data)
    for res in img_res:
        img_response = requests.get(res)
        img_data = img_response.content
        img_name = res.split("/")[-1]
        print(res)
        with open(img_name, "wb") as fw:
            fw.write(img_data)
            fw.flush()
            print("成功")


推荐阅读