path
中,配置環境變量後建議重啓系統以便生效。
若是你用的pip
,執行html
pip install Selenium
可是我用的是Anconda
python
conda install Selenium
#!/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()