1. Install selenium

  1. install selenium

pycharm-->File-->Settings-->Python Interpreter-->As shown below, install the selenium package:

After the installation is successful, it will be displayed in the list:

  1. Install browser driver

Download address of each browser driver
1. GeckoDriver (Firefox): https://github.com/mozilla/geckodriver/releases
2. ChromeDriver (Chrome) : https://sites.google.com/a/chromium.org/chromedriver /home or https://chromedriver.storage.googleapis.com/index.html
3. IEDriverServer (IE): http://selenium-release.storage.googleapis.com/index.html
4. OperaDriver (Opera): https ://github.com/operasoftware/operachromiumdriver/releases
5. Microsoft Web Driver (Edge): https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver

Set browser driver:

  1. Manually create a directory to store browser drivers, such as D:\drivers

  1. Put the downloaded driver file in this directory;

  1. 右击此电脑,在右键菜单中点击“属性--高级系统设置--高级--环境变量--系统变量--Path”

  1. 将“D:\drivers”添加到Path中

3、验证

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

运行该程序,会打开chrome并跳转百度页面。

Guess you like

Origin blog.csdn.net/qq_40384309/article/details/129665125