使用 python 上傳圖片來控制 selenium。它工作完美,但由于某種原因它復制了圖像。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 日志上傳后的畫面: 畫面動圖:https://i.stack.imgur.com/018SA.gif
1 回答

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
要刪除重復的圖像,您可以一次上傳所有圖像,這樣所有圖像都將作為重復上傳。
myElem.send_keys(“imagePath1” + \n + “imagePath2”)
添加回答
舉報
0/150
提交
取消