The latest version of python + Selenium automation environment construction

						python环境搭建

1. Open the python official website ( https://www.python.org/ )

2. Download python
Method 1: Click to download the latest version directly as shown in the figure
insert image description here
Method 2: Download the corresponding version Click on windows as shown in the figure:
insert image description here
insert image description here
Or click the corresponding version to download:
insert image description here
insert image description here

3. Install the program after the download
is complete: 1. Find the installation file for download:
insert image description here
2. Click to install
insert image description here
insert image description here
insert image description hereinsert image description here
insert image description here
## According to the user's own decision (the blogger has not disabled it)
insert image description here
4. After the installation is complete, check whether the system environment variable is added
(the latest version of win10 The property page that may be opened is different)
insert image description here
new version
insert image description here
old version
insert image description here
insert image description here
insert image description here
insert image description here
// If you do not click to automatically add to the system environment variable during the installation process, the user can add it manually

5. Start CMD (win (referring to the win key with an icon on the keyboard) + r)
1. After entering cmd, it will enter the command prompt window interface
insert image description here
2. Enter python
insert image description here
3. Enter exit() to exit
insert image description here
4. Enter pip or pip list
insert image description here
insert image description here
5. If you don’t know what directory python is installed in, you can use the command to find it or check it according to the environment variables of the system.
insert image description here
6. The above are the steps to install the python environment.

						selenium环境安装

Note: Please complete the python installation when installing the selenium environment.
1. Open the cmd command prompt window
and enter pip install selenium to install the latest version directly
Note: pip install selenium==version number, you can download the corresponding version of selenium.
View version: Enter a random version number to display all versions. As shown in the figure
insert image description here
2. Install with version 3.141.0
// The following picture appears, which may be due to the network.
insert image description here
The following installation is complete
insert image description here
3. After the installation is successful, enter python, enter the shell mode, enter from selenium import webdriver, no error means that selenium is installed success.
insert image description here
4. You can also enter pip show selenium to view the installed selenium version.
Uninstall: pip uninstall selenium
Install or upgrade: pip install -U selenium
insert image description here
5. Enter the following code and run it (the blogger runs it under the pycharm editor) and
the result as shown in the figure will appear

from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
sleep(3)
driver.quit()

insert image description here
Solution:
browser driver installation
Firefox installation driver
download address ( https://github.com/mozilla/geckodriver/releases/ )
1. Download by yourself according to the system version (the blogger’s browser and driver take the latest download as an example)
insert image description here
2 . After the download is complete, extract it to the root directory of python:
insert image description here
Chrome installation driver
download address ( http://npm.taobao.org/mirrors/chromedriver/ )
1. Select the corresponding version (browser 64 can download 32-bit backward compatible)
insert image description here
3. Unzip the downloaded driver and put it in the python root directory:
insert image description here
re-run the code just now to successfully open the browser and run:
insert image description here

Guess you like

Origin blog.csdn.net/AnnyXSX/article/details/118407080