使用python上传图像以控制硒。它可以完美工作,但由于某种原因会复制图像。
IE-上传第一张图片确认为主图片后上传。上传第二张图片上传第三张图片+重新上传2张图片等...
使用此代码
for pair in pair_list:
file = pathlib.Path(pair)
if file.exists ():
#HERE I RESIZE PHOTO
basewidth = 580
img = Image.open(pair)
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
newName = pair.replace('.jpg','_resized.jpg')
img.save(newName, quality = 95)
pair = newName
myImagesToDelete.append(pair)
#END OF RESIZE
#print('Uploading photo:' + pair)
if firstpic == True:
firstpic = False
#ADD MAIN PICTURE
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'img-file-input')))
myElem.send_keys(pair)
except TimeoutException:
errorDuringFill = True
time.sleep(5)
print('First picture added ' + pair)
#CONFIRM PICTURE
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/main/div[2]/div/div/div[2]/section[1]/div/div[2]/div[2]/div[2]/div[3]/div/button[2]')))
myElem.click()
except TimeoutException:
errorDuringFill = True
print('First picture confirmed')
else:
#ADD OTHER PICTURES
print('Adding it as other picture: ' + pair)
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'img-file-input')))
myElem.send_keys(pair)
except TimeoutException:
errorDuringFill = True
#time.sleep(2)
路径是好的,我可以在日志中看到循环是好的。在总共5个循环中,我添加了8张图像。
所示的Python日志日志:Python日志
要删除重复的图像,您可以一次上传所有图像,因此所有图像将作为重复图像上传。
myElem.send_keys(“imagePath1” + \n + “imagePath2”)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句