簡述:html
開始接觸python寫web自動化的腳本主要源於在公司訂閱會議室,主要是使用python+selenium+chromedriver驅動chrome瀏覽器來完成的,其中部分python代碼能夠經過低版本的Firefox來錄製,生成腳本。安裝好環境以後,基本就是用火狐生成一些代碼,而代碼生成就是根據web中元素的id或者一些其餘特徵去定位html中的組件,而後模擬鼠標和鍵盤操做,實現自動化控制,調試完成能夠用pyinstaller生成exe文件。python
環境搭建:git
一、下載chrome瀏覽器和對應版本的chromedrivergithub
版本對應關係能夠參照這個帖子:https://blog.csdn.net/a6864657/article/details/80616418web
http://chromedriver.storage.googleapis.com/index.htmlchrome
下載好將解壓後的 放入chrome.exe 同級目錄api
二、安裝python,配置python的和pip的環境變量瀏覽器
三、安裝selinium pip install selinium便可ide
Firefox錄製python腳本ui
可參考:https://blog.csdn.net/weixin_37979468/article/details/83621394
公司代碼沒法看到,因此只寫了個驅動瀏覽器的代碼示例,其餘地方能夠把火狐生成的python直接替換便可:
from selenium import webdriver #executable_path = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver_X64.exe' driverChrome = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe") driverChrome.maximize_window() driverChrome.get("http://www.dianping.com/") driverChrome.quit()
參考教程:
官方文檔 : Selenium with Python