selenium4 selenium_handless的使用

Hbro發表於2024-08-05
# 封裝handless

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
def share_browser():
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
service = Service("chromedriver.exe")
browser = webdriver.Chrome(options=chrome_options,service=service)
return browser

browser = share_browser()
url = 'https://www.baidu.com'
browser.get(url)

相關文章