Chrome browser driver installation

First of all, please make sure that your Chrome browser has been installed, and the Chrome version is: 71.0.3578.98 (official version) (64-bit)

1. Mac computer one-click installation method

Open the Mac terminal terminal and enter the command:

curl -s https://localprod.pandateacher.com/python-manuscript/crawler-html/chromedriver/chromedriver-for-Macos.sh | bash
wait for the program installation to complete.

Two, Windows system installation method

2.1 The driver version downloaded and installed this time is: 2.44

ChromeDriver download address: http://npm.taobao.org/mirrors/chromedriver/2.44/
Click the download link above, select the corresponding version to download, decompress the downloaded chromedriver_win32.zip and it will be an exe file, copy it to Just in the root directory of your Python installation.

2.2 Windows system to find the Python root directory method

In the Windows system, everyone's Python installation directory is different from person to person, you need to find the python installation folder in your computer

For example, the installation path of the following computer is:
C:\Users\win\AppData\Local\Programs\Python\Python37

If you can't find your own Python installation path, you can try to find it by running the following command line in the Python IDE:

import sys
for i in sys.path:
    print(i)

The running results will be similar to those shown in the figure below:
Python installation path query
From the results, we can see some rules:

The blue box refers to your Python installation directory. The path in front of the blue box varies from person to person, while the path on the right of the blue box is the same for everyone.

All you have to do is to find the folder shown in the blue box on your computer (remember: yours may not be the [C:\Users\win\AppData\Local\Programs\Python\Python37] file in the illustration folder)

Then, just put chromedriver in this folder.

2.3 Place the browser driver in the Python root directory

Place the browser driver in the Python root directory
If you put the file in the root directory of Python according to the method just mentioned, if ChromeDriver still cannot be used, then you need to configure environment variables.

2.4 How to configure environment variables

First, right-click [This PC] and select [Properties]:
Right-click [This PC] and select [Properties]

Path address added
(1) In the pop-up dialog box, select advanced system settings;
(2) Select environment variables;
(3) Double-click [Path] in the system variables;
(4) Click New;
(5) Install the Python installation root you just found Paste the path to the end, for example:
C:\Users\win\AppData\Local\Programs\Python\Python37
Note: Remember to add ";" (English semicolon)
(6) Click OK to close the dialog box, and the system variables are configured alright.

3. Results Verification

Edit the following code

from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://www.baidu.com/')#模拟打开百度网页

Click Run, the following pop-up window will appear
automatically open browser

Guess you like

Origin blog.csdn.net/qq_42132821/article/details/105923365