Detailed explanation of selenium usage takes chrome as an example

Selenium is a complete web application testing system, including test recording (selenium IDE), writing and running (Selenium Remote Control) and parallel processing of tests (Selenium Grid). The core of Selenium Selenium Core is based on JsUnit and is written entirely in JavaScript, so it can be used on any browser that supports JavaScript.

Selenium can simulate real browsers, automated testing tools, support multiple browsers, and is mainly used in crawlers to solve JavaScript rendering problems.

Step 1: Install selenium

pip install selenium from the command line

 

Step 2: Configure the browser driver

 

Take chrome browser as an example,

First update the latest version of chorme. Of course you can not update it.

Corresponding to the following website, find the driver corresponding to chrome

http://chromedriver.storage.googleapis.com/index.html

 Be sure to find the corresponding version, or it is not easy to report errors. The error will report that get is missing a parameter or  

The statement browser = webdriver.Chrome() is wrong. It's actually a driver error.

Copy the downloaded chromedriver.exe to the chrome installation directory, and add the installation path to the PATH.

 

Step 3: Test

 

from selenium import webdriver
browser = webdriver.Chrome()
browser.get( ' https://www.baidu.com ' )
 print (browser.page_source)   # browser.page_source is to get all the html of the webpage 
browser.close()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325042332&siteId=291194637