Selenium + Python3 reptiles
Ready to work
Chrome Driver Download (normal access and download), according to their chrome version Download
Download and unzip the configuration environment variable path
in 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()