環境準備
已正確安裝python環境,已安裝chrome瀏覽器或者firefox瀏覽器
使用 python --version 命令如果輸出python版本則python 安裝成功
安裝selenium
使用pip命令安裝selenium
- pip install selenium
下載chrome驅動 或者firefox驅動
selenium的chrome驅動(國內阿里像)
selenium的firefox驅動(github地址)
注意:下載對應版本的驅, 點擊瀏覽器三個點 - 幫助 - 關于Google Chrome 即可查看瀏覽器版本
將驅動放入環境變量
因為python 目錄是直接就在環境變量下的,可直接將驅動放于python目錄下
編寫代碼測試selenium
- from selenium import webdriver
- import time
- def hello():
- driver = webdriver.Chrome()
- driver.get("https://www.baidu.com/")
- time.sleep(3)
- driver.quit()
- if __name__ == '__main__':
- hello()
如果能夠上面代碼能夠正常打開瀏覽器,就說明selenium已經安裝成功了
下一篇將編寫關于selenium 的具體使用
到此這篇關于Python中使用Selenium環境安裝的方法步驟的文章就介紹到這了,更多相關Python Selenium環境安裝內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/qq_24269969/article/details/111154394