安裝套件(Anaconda環境):
conda install -c conda-forge selenium
conda install -c conda-forge webdriver-manager
如: chromedriver_win32.zip
解壓縮後:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
“””匯入Selenium庫所需的模組,
其中包括 webdriver、Options和Service。”””
options = Options()
options.add_argument("--disable-notifications")
“””創建一個Options對象,
使用add_argument方法設置Chrome瀏覽器的選項。
在這個例子中,
使用–disable-notifications選項禁用瀏覽器通知。”””
driverpath = r"P:\Python\selenium\chromedriver_win32\chromedriver.exe"
#定義Chrome WebDriver的路徑
service = Service(driverpath)
chrome = webdriver.Chrome(service=service, options=options)
“””創建一個Service對象,
並傳遞driverpath路徑以告訴Selenium要使用的驅動程序的位置。
然後,用service變量初始化webdriver.Chrome。”””
chrome.get("https://www.facebook.com")
#使用get方法將瀏覽器導航到Facebook的網站。

執行結果:
自動打開chrome瀏覽器
連線facebook:

推薦hahow線上學習python: https://igrape.net/30afN
如果出現以下錯誤的話:
SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 113
Current browser version is 118.0.5993.118 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
可以將Chrome(118)降級為
同ChromeDriver(113)


![Python如何寫入docx文件? from docx import Document ; doc = Document() ; table = doc.add_table(rows=5, cols=3) ; table.cell(r,c).text = str(tabs[r][c]) ; doc.add_heading ; p = doc.add_paragraph ; p.add_run ; doc.add_picture ; 使用wordPad開啟會少最後一個row,可以用免費的LibreOffice Python如何寫入docx文件? from docx import Document ; doc = Document() ; table = doc.add_table(rows=5, cols=3) ; table.cell(r,c).text = str(tabs[r][c]) ; doc.add_heading ; p = doc.add_paragraph ; p.add_run ; doc.add_picture ; 使用wordPad開啟會少最後一個row,可以用免費的LibreOffice](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220914154313_30.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python TQC 510 費氏數列,list[], f.append(n3) Python TQC 510 費氏數列,list[], f.append(n3)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220522152013_66.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python `typing.NamedTuple` (`collections.namedtuple`) 與 `typing.Literal` 教學 — 用型別「防止錯配」; StripRule = NamedTuple(“StripRule”, [(“regex”, re.Pattern), (“flag”, str)]) vs StripRule = namedtuple(“StripRule”, [“regex”, “flag”]) Python `typing.NamedTuple` (`collections.namedtuple`) 與 `typing.Literal` 教學 — 用型別「防止錯配」; StripRule = NamedTuple(“StripRule”, [(“regex”, re.Pattern), (“flag”, str)]) vs StripRule = namedtuple(“StripRule”, [“regex”, “flag”])](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2026/07/20260702150603_0_86abc2.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/06/20230626093403_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言