セレンPythonの爬虫類

セレン+のpython3爬虫類

準備

クロームドライバのダウンロード(通常のアクセスおよびダウンロード)、彼らのクロームバージョンをダウンロードに従って

Chromeバージョン ダウンロード
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/

ダウンロードと設定環境変数解凍しpath、構成環境変数には、有効にするには、システムを再起動することをお勧めします。


セレンのインストール・ライブラリー

あなたが使用している場合はpip、実行を

pip install Selenium

しかし、私は使用しますAnconda

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()

おすすめ

転載: www.cnblogs.com/zhangqiuchi/p/12151955.html