#encoding=utf-8
import requests
import re
import os
url='https://unsplash.com'
head={'User-Agent': 'Mozilla/5.0'}
rsp=requests.get(url,headers=head)
#print(rsp)
html=rsp.content.decode('utf-8')
# print(html)
pattern=re.compile(r'<img class=".*?srcSet="(.*?)"',flags=re.S)
image_list=pattern.findall(str(html))
print(image_list)
cwd=os.getcwd()
file_name = os.path.join(cwd,'图片')
if not os.path.exists('图片'):
os.mkdir(file_name)
n=0
for src in image_list:
image_data = requests.get(url=src, headers=head).content
with open(file_name+str(n),'w')as f:
f.write(str(image_data))
n+=1
这是我的代码(这个代码还没写完!图片后缀我还不知道,要加上图片后缀才行)
问:像我上面说的一样,如何不使用绝对路径去打开那文件夹?
做事不要太绝嘛
如果我问题没描述清楚,还请指出