自測項目:批量刪除雲盤重復文件
阿新 • • 發佈:2019-03-13
and ngram ins drive ont word for xpath ear
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()
自測項目:批量刪除雲盤重復文件