import os
search_word = input(‘请输入要查找的吧名’)
创建文件夹
if not os.path.exists(search_word):
os.mkdir(search_word)
else:
print(search_word + ‘文件夹已存在’)
# 生成文件名
filename = search_word + '_' + str(page) + '.html'
file_path = search_word + '/' + filename
# 将内容写进文件
if not os.path.exists(file_path):
print('正在下载第%s页数据...' % page)
with open(file_path, 'wb') as fp:
fp.write(response.read())
else:
print(file_path + '文件夹已存在')