自测项目:批量删除云盘重复文件
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support.wait import WebDriverWait import time from yunpan_quchong import repeats ##1.找到搜索框,输入文件名,回车 ##2.找到所有多选框,选中除第一个外所有文件 ##3.找到删除,点击 ##4.找到弹出窗口的确认删除,点击 def login(name,pwd): ##打开云盘并登录 try: global b b=webdriver.Firefox() b.get('https://pan.baidu.com') ##找到账号密码登录 time.sleep(5) login=b.find_element_by_xpath('//div[@class="tang-pass-footerBar"]/p[2]') login.click() name=b.find_element_by_id('TANGRAM__PSP_4__userName').send_keys(name) pwd=b.find_element_by_id('TANGRAM__PSP_4__password').send_keys(pwd) try: b.find_element_by_xpath('//input[@id="TANGRAM__PSP_4__memberPass" and @checked="checked"]').click() except: print('自动登录没有选中,跳过!') time.sleep(8) btn=b.find_element_by_id('TANGRAM__PSP_4__submit').click() time.sleep(15) except: print('没有加载到云盘页面') def del_file(filename): #搜索同名文件 search=b.find_element_by_xpath('//input[@class="bbgrbvde"]') search.click() time.sleep(1) search.send_keys(filename) time.sleep(1) search.send_keys(Keys.ENTER) time.sleep(1) #选中第一个文件外文件 files=b.find_elements_by_xpath('//span[@class="EOGexf"]') for file in files[1:]: file.click() #删除 time.sleep(1) del1=b.find_element_by_xpath('//a[@class="g-button" and @title="删除"]').click() sure=b.find_element_by_xpath('//a[@title="确定"]').click() time.sleep(5) clear=b.find_element_by_xpath('//span[contains(@class,"osbyQyd2")]').click() def main(): login('name','pwd') for file in repeats(): del_file(file) if __name__=='__main__': main()