1. 程式人生 > >python 實現自動上傳檔案到百度網盤(附程式原始碼及實現過程)

python 實現自動上傳檔案到百度網盤(附程式原始碼及實現過程)

5、編寫AutoIt指令碼,實現檔案上傳 1.開啟scite script editor 程式碼如下: # coding=utf-8 import time from selenium import webdriver driver = webdriver.Firefox() #開啟火狐瀏覽器 driver.get('http://www.baidu.com') #開啟百度介面 driver.find_element_by_id('kw').send_keys('China') #在搜尋框內輸入想要搜尋內容 time.sleep(2) # 瀏覽器載入需要時間 driver.find_element_by_id('su').click() #搜尋完成
這塊的程式碼編寫完成後,先測試下。 tools---》Go 執行無誤後,然後把au3檔案轉換成exe。 4. 使用compile script to exe將上述AutoIt指令碼編譯為exe檔案供python指令碼呼叫
點選ok即可。 6、最後,使用Python指令碼呼叫AutoIT指令碼 完整程式碼如下: import os from selenium import webdriver import time #class Connect(): UserName = '' PassWord = '' URL = 'https://pan.baidu.com/' driver = webdriver.Firefox() driver.get(URL) driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[6]/div/div[6]/div[2]/a').click() driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[6]/div/div[3]/form/p[5]/input[2]').send_keys(UserName ) driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[6]/div/div[3]/form/p[6]/input[2]').send_keys(PassWord ) driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[6]/div/div[3]/form/p[9]/input').click() time.sleep(30) #設定按鈕響應的時間 sreach_window = driver.current_window_handle #此行程式碼用來定位當前頁面 driver.find_element_by_xpath('//*[@id="h5Input0"]').click() os.system(r'C:\\Users\xx\Desktop\upfile.exe') 我的執行結果如下: