python crawler bulk download beautiful lady

Lemon scent,
cookie-like fluffy,
scattered colorful lead powder,
smiling at you is cardamom me

Getting started with reptiles, start by downloading the original images of Miss Aesthetic in bulk ...

Insert picture description here
Insert picture description here

  • code show as below:
import requests
import re
import os
import time

# 伪装
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}

# 请求网页
response = requests.get("https://www.vmgirls.com/3907.html", headers=headers)
html = response.text

# 解析网页
urls = re.findall('<img alt=".*?" src=".*?" width=".*?" height=".*?" class=".*?" data-src="(.*?)" data-nclazyload="true" data-srcset=".*">',html)
print(urls)

# 下载目录(以主题命名目录,新建目录)
dir_name = re.findall('<h1 class="post-title h3">(.*?)</h1>', html)[-1]
if not os.path.exists(dir_name):
    os.mkdir(dir_name)

# 下载图片
for url in urls:
    # 相隔1s
    time.sleep(1)
    # 图片的名字
    file_name = url.split('/')[-1]
    response = requests.get(url, headers=headers)
    # 保存
    with open(dir_name + "/" + file_name, 'wb') as f:
        f.write(response.content)

  • Results are stored in the directory
    Insert picture description here
Published 141 original articles · Like 318 · Visit 270,000+

Guess you like

Origin blog.csdn.net/Sunny_Future/article/details/105420916