def mk_file_get_num():
last_dir = "./img"
dir = "./img/" + keyword
if os.path.exists(last_dir):
if os.path.exists(dir):
print("文件夹已经存在")
else:
os.mkdir(dir)
print(dir + "已经创建成功")
else:
os.mkdir(last_dir)
if os.path.exists(dir):
print("文件夹已经存在")
else:
os.mkdir(dir)
print(dir + "已经创建成功")
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
}
def get_img():
mk_file_get_num()
num = input("------请输入要下载美女页数:")
list_all = []
for i in range(1,int(num),1):
# print(i)
url = 'https://www.mmonly.cc/mmtp/list_9_'+str(i)+'.html'
print(f'-----------------打印第{i}页-----------------')
print(url)
response_data = requests.get(url, headers=headers)
response_data.encoding = response_data.apparent_encoding
html = response_data.text
parrent = re.compile('<img width=.*?alt="(.*?)" src=.*?original="(.*?)"></a></div>', re.S)
img_links = re.findall(parrent, html)
sleep(1)
for item_link in img_links:
dict_all = {}
dict_all['name'] = item_link[0].strip()
dict_all['link'] = item_link[1].strip()
list_all.append(dict_all)
return list_all
def write_to_file():
list_img = get_img()
count_img = len(list_img)
print(count_img)
for i in range(count_img):
img_dict = list_img
name = img_dict.get('name')
link = img_dict.get('link')
response_data = requests.get(link, headers=headers)
with open('./img/'+keyword+'/'+name+'.jpg', 'wb') as f:
f.write(response_data.content)