import urllib.request
import re
page_number = 1
def load_source(website):
site = urllib.request.urlopen(website)
read_site = site.read()
return read_site
def parse_img(source):
links = []
t = str(source)
pattern = '<img width="\d+" height="\d+" src="'
result = re.split(pattern, t)
# рабочий вариант через replace
# t = str(source).replace('550', ' ').replace('375', ' ').split('<img width=" " height=" " src="')
for i in result:
r = str(i).split('""')
links.append(r[0])
return links
def download(links):
name = 1
for i in links:
try:
v = urllib.request.urlopen(i)
f = open('Стр' + str(page_number) + 'номер' + str(name) + '.jpg', 'wb')
f.write(v.read())
f.close()
name += 1
except:
pass
def main():
print('start page: ')
print()
source = load_source('https://aliholic.com/shop/')
links = parse_img(source)
download(links)
print('Tnx')
if __name__=='__main__':
main()