python 重复图片_硒python重复图像

Using python to upload images to control over selenium. It works perfect but for some reason it duplicate the images.

I.E - First image is uploaded

Upload as main picture is confirmed.

Second image is uploaded

Third images is uploaded + 2 image re uploaded etc ...

Using this code

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)

Paths is good which i can see in log

Loops are good.

in total of 5 loops i have 8 images added.

Python log log as it shows:

Python log

Screen after upload :

Screen

GIF :

解决方案

For removing duplicate images, you can upload all images at one time so all images will be uploaded as duplicate.

myElem.send_keys(“imagePath1” + \n + “imagePath2”)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值