艺术图片保存

"""请求网页"""

import requests,  re, time, os

headers = {

'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '

'Chrome/80.0.3987.106 Safari/537.36 Edg/80.0.361.54'

}

response = requests.get('https://www.vmgirls.com/12985.html', headers=headers)

html = response.text

#

"""解析网页"""

# https://static.vmgirls.com/image/2019/10/470B6B0D-609A-4A84-A533-351AF30F3927-1-scaled.jpeg

urls = re.findall('', html)

#

秋日温柔,人间理想

dir_name = re.findall('

(.*?)

', html)[-1]

if not os.path.exists(dir_name):

os.mkdir(dir_name)

# 正则表达式

print(urls)

'''保存图片'''

for urlin urls:

# 图片名字

    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)

你可能感兴趣的:(艺术图片保存)