An introduction
# Selenium was originally an automated testing tool, and reptiles use it mainly to solve the problem requests can not be directly executed JavaScript code. # Selenium is essentially driven by the browser, fully simulate the operation of the browser, such as jumps, input, click the drop-down, etc., to get the results after page rendering to support multiple browsers. The main use it to skip the login authentication from selenium import webdriver # Google Chrome browser=webdriver.Chrome() # Firefox browser browser=webdriver.Firefox() No browser interface # browser=webdriver.PhantomJS() # Apple's browser browser=webdriver.Safari() # IE browser browser=webdriver.Edge()
Two assembling
# Installation: the Selenium + chromedriver pip3 install selenium Download chromdriver.exe into the scripts directory python installation path can pay attention to the latest version Yes 2. 38 , not 2. 9 domestic mirror site address: HTTP: // npm.taobao.org/mirrors/chromedriver/2.38/ latest the network version Quguan find: HTTPS: // sites.google.com/a/chromium.org/chromedriver/downloads # Verifying the Installation C:\Users\Administrator>python3 Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from selenium import webdriver >>> driver=webdriver.Chrome() #弹出浏览器 >>> driver.get('https://www.baidu.com') >>> driver.page_source #note: selenium3 supported by default webdriver is Firfox, and Firefox will need to install geckodriver Download Link: HTTPS: // github.com/mozilla/geckodriver/releases selenium+chromedriver
Download selenium request library can also be done directly in Pycharm
You can modify the source to download the Tsinghua source
-D:\python36\Lib\site-packages\pip\models\index.py
-PyPI = index('https://pypi.tuna.tsinghua.edu.cn/simple')
Three use the program to launch Google Chrome
from selenium import webdriver import time Driver = Find drive folder webdriver.Chrome () # files directly to the Script #driver = webdriver.Chrome (R & lt ' C: \ the Users \ the Dell \ Downloads \ chromedriver.exe ' ) # fill drive path the time.sleep ( 5 ) # launch Google Chrome five seconds Automatically close your browser driver.close () # open time to meet