Skip to content

Commit

Permalink
selenium,2022/9/17 將套件更新到4.4.3版本,因此寫法全部都更新過
Browse files Browse the repository at this point in the history
selenium,2022/9/17 將套件更新到4.4.3版本,因此寫法全部都更新過
  • Loading branch information
rifleak74 authored Sep 19, 2022
1 parent 744f8f7 commit 015117e
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@
第二章 進階皇蟲Selenium
Selenium環境設定與測試
"""
from selenium.webdriver import DesiredCapabilities
# selenium,2022/9/17 將套件更新到4.4.3版本,因此寫法全部都更新過
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

# 設定基本參數
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
#此處必須換成自己電腦的User-Agent
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'

# PhantomJS driver 路徑
driver = webdriver.PhantomJS(executable_path = 'phantomjs', desired_capabilities=desired_capabilities)
# 自動下載ChromeDriver
service = ChromeService(executable_path=ChromeDriverManager().install())

# 關閉通知提醒
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
# 以下三個註解打開,瀏覽器就不會開啟
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_experimental_option("prefs",prefs)

# 開啟瀏覽器
driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
driver = webdriver.Chrome(service=service, chrome_options=chrome_options)
time.sleep(5)

# 去到你想要的網頁
driver.get("https://www.ubereats.com/tw")

0 comments on commit 015117e

Please sign in to comment.