Python + Selenium 動態爬蟲

試用 Pythone 試作簡單的動態爬蟲。Jupyter Notebook, Selenium, WebDriver.

安裝 Selenium

pip install selenium

前置安裝請參考

Python 第一支爬蟲(Jupyter Notebook)chevron-right


指令紀錄

開啟 Google 搜尋網頁

# 載入需要的套件
from selenium import webdriver

# 開啟瀏覽器視窗(Chrome)
driver = webdriver.Chrome()

# 開啟相標網頁:Google 搜尋引擎
driver.get("https://www.google.com/")

填入關鍵字並送出搜尋

解析搜尋結果/清單

關閉瀏覽器視窗

circle-exclamation


沒圖沒真象

參考資料

動態網頁爬蟲第一道鎖 — Selenium教學:如何使用Webdriver、send_keys(附Python 程式碼)arrow-up-right ------ 指令已過時,開發流程仍有參考性。

AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'arrow-up-right ------ 新舊版指令遷移,如:

(EOF)

Last updated