Python Selenium quick installation configuration (including ChromeDriver network disk download)

foreword

Selenium is a good thing. We can use Python to perform many interesting automation operations on the browser.
For example, automatic sign-in in forums or post bars or even posting posts to earn points, and another example is automatic acquisition of some web page information.
Here is just a simple introductory tutorial from installation to use.
The test time is November 26, 2019.
The Chrome version is Version 78.0.3904.97 (Official Build) (64-bit)

environment

Ubuntu 18.04
Chrome version: Version 78.0.3904.97 (Official Build) (64-bit)
You also need to download the corresponding version of ChromeDriver and third-party library Selenium

Need to download:

ChromeDriver
official website download address: https://sites.google.com/a/chromium.org/chromedriver/home
Note: Find ChromeDriver 78.0.3904.105 and download it.
insert image description here

installation steps

1. Download selenium

1. Check the pip version and the corresponding Python version to prevent your pip installation from corresponding to the wrong Python

pip -V
# 输出如下:
# pip 19.3.1 from /home/hyh/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
pip install pip --upgrade 

2. Install Selenium

pip install selenium

2. Install ChromeDriver

2.1 View Chrome version My Chrome version is:

Version 78.0.3904.97 (Official Build) (64-bit)

2.2 Download and install the corresponding version of ChromeDriver

ChromeDriver official website download address: https://sites.google.com/a/chromium.org/chromedriver/home
Note: 1. Find ChromeDriver 78.0.3904.105 and download it. I will upload this version of ChromeDriver to Baidu Netdisk for self-collection , self-serve at the bottom of the article. If you need other versions, please leave a message, and I will update the version you need to the network disk after I see it.
Note: 2. Here I download and decompress it to the /home/hyh/2019_Software/ChromeDriver/ directory.

The specific command line is as follows.

cd /home/hyh/2019_Software/ChromeDriver/
wget https://chromedriver.storage.googleapis.com/78.0.3904.105/chromedriver_linux64.zip
unzip  chromedriver_linux64.zip
# 解压文件为:chromedriver
# 此时ChromeDriver 路径为:/home/hyh/2019_Software/ChromeDriver/chromedriver

insert image description here

So far, all the environment configurations have been successfully installed, and now start testing.

3. Test example

from selenium import webdriver
import time

if __name__ == '__main__':
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    # 注:请注意这一行,"/home/hyh/2019_Software/ChromeDriver/chromedriver"为刚刚解压的chromedriver文件路径
    driver = webdriver.Chrome(executable_path="/home/hyh/2019_Software/ChromeDriver/chromedriver",chrome_options=options)
    driver.get('https://www.baidu.com')
    print(driver.title)
    time.sleep(1)
    driver.close()

The browser can automatically open the Baidu website, and output "Baidu, you will know"
and the environment configuration is completed.

other

1. Regarding the interactive behavior of web page element positioning, sending information, and clicking buttons, you can check the Selenium official website documents for learning.
Selenium official tutorial: https://selenium-python.readthedocs.io/
(The next article may describe the function of earning points for simple website daily sign-in and reply)

2. ChromeDriver 78.0.3904.105 network disk download (including corresponding versions of Linux, Mac, and Windows):
Link: https://pan.baidu.com/s/13XUfK60NxReiVXEa_TMG_A
Extraction code: 61pr


If you have any questions, please point them out.
If you have any questions, please
leave a message. If you need another version of ChromeDriver, please leave a message. If there is a version, you will continue to update the network disk.

Test passed on November 26, 2019

Stay on September 18, 2021:
The latest version of ChromeDriver download (version 93.0, including Windows, Linux, Mac) has been updated.
Please check the latest blog: Python calls Google Translate_selenium version (available for testing in September 2021)

Guess you like

Origin blog.csdn.net/xiaozi_001/article/details/103259890