硒python重复图像 [英] Selenium python duplicate images

查看:193
本文介绍了硒python重复图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python上传图像以控制硒.它可以完美工作,但由于某种原因会复制图像.

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

IE.E-上传第一张图片 确认作为主图片上传. 第二张图片已上传 上传了第三张图片+重新上传了2张图片...

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 ...

使用此代码

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张图像.

Paths is good which i can see in log Loops are good. in total of 5 loops i have 8 images added.

Python日志日志,如下所示: Python日志

Python log log as it shows: Python log

上传后的屏幕: 屏幕

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")

这篇关于硒python重复图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆