Selenium python reptile

Selenium + Python3 reptiles

Ready to work

Chrome Driver Download (normal access and download), according to their chrome version Download

Chrome version download link
78 https://chromedriver.storage.googleapis.com/index.html?path=78.0.3904.70/
79 https://chromedriver.storage.googleapis.com/index.html?path=79.0.3945.36/
80 https://chromedriver.storage.googleapis.com/index.html?path=80.0.3987.16/

Download and unzip the configuration environment variable pathin the configuration environment variable is recommended to reboot the system to take effect.


Selenium installation library

If you are using pip, execution

pip install Selenium

But I useAnconda

conda install Selenium

Reptile start

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Chrome()
driver.get("https://www.jianshu.com")
try:
    titles = driver.find_elements_by_class_name('title')
    for ti in titles:
        print(ti.text)
        print('\n-----------------')
except NoSuchElementException as e:
    print(e)
finally:
    driver.close()

Guess you like

Origin www.cnblogs.com/zhangqiuchi/p/12151955.html