Hej Everyone,
The idea of the script is to grab image links from a catalogue page of my company's website and change them to image links with a higher resolution and filter for image format, where the variable to filter for is found in the link itself, in this case the capital P. Afterwards a csv is generated with the links.
The transformation, filtering and writing to csv works fine, but my problem is that I don't want all the 80 products, I only want 8 to be in the list nl.
The links list contains elements like this one https://rndr.mywebsite.com/media/catalog/product/seo-cache/x386/19/95/19-95-101P/How-Hard-You-Hit-Butcher-Billy-Premium-Poster.jpg
NOTE: variables ratio and creatives (inputnumber-1) are defined by commandline input. Just assume that the input was ratio = P and creatives = 9-1.
NOTE2: For quicker testing, the links list has a limit of 15 elements by now.
nl= []
string1= "https://rndr.mywebsite.com/media/catalog/product/cache/x800/"
string2= ".jpg"
while len(nl) <= creatives:
for index in range(len(links)):
if "P" in "".join(links[index].split("/", 12)[10]) and "P" in ratio:
print("YEAH", len(nl))
nl.extend([string1 + "/".join(links[index].split("/", 11)[8:11]) + string2])
else:
print ("Ups", len(nl))
print (nl)
The actual output is
('YEAH', 0)
('YEAH', 1)
('YEAH', 2)
('YEAH', 3)
('Ups', 4)
('YEAH', 4)
('YEAH', 5)
('Ups', 6)
('YEAH', 6)
('YEAH', 7)
('YEAH', 8)
('YEAH', 9)
('YEAH', 10)
('YEAH', 11)
('YEAH', 12)
[https://rndr.mywebsite.com/media/catalog/product/cache/x800/19/95/19-95-101P.jpg, transformed-link2,...,transformed-link12]
As you can see the filtering and transforming works fine, but it should stop after having 9 links in the list nl.
nlwith another list of, I don't know what size inside another loop. You're probably overshooting the limit before the next check can be done.