1.更換Python版本html
打開pycharm,點擊 file——setting——project項目名——project Interpreter,點擊右側的設置,以下圖python
選擇新Python版本的安裝路徑。web
若是location提示「environment location directory is not empty」,致使沒法保存。則將location路徑的文件夾刪掉,而後再從新設置就能夠保存了。chrome
2.添加selenium包windows
沒有安裝selenium包時,程序中importselenium包報錯:api
查看Python3安裝目錄 ..\python37\Script\目錄下是否存在pip.exe,並確保該目錄已添加到「環境變量」的「path」下面。google
打開windows命令提示符,輸入「pip」命令,確保該命令能夠執行成功。spa
而後按照安裝selenium包。3d
輸入命令:pip install selenium orm
安裝成功後,輸入:from selenium import selenium
不報錯,表示selenium包安裝成功
而後在從新配置project interpret,步驟與1相同。
3.添加Chromedriver包
常見報錯:
driver = webdriver.Chorme()
AttributeError: module 'selenium.webdriver' has no attribute 'Chorme'
查找Chrome版本對應的Chromedriver版本:https://chromedriver.storage.googleapis.com/index.html
下載相應的版本後,將 Chromedriver.exe 放到Chrome安裝目錄下
配置環境變量:將Chromedriver.exe的路徑加到環境變量path中
檢驗是否添加成功:
打開cmd,輸入 Chromedriver。以下圖,安裝成功。
思考:
上面都操做成功了,運行下面程序報錯