Python Selenium Headless Threading



我有这个Python Selenium Threading脚本,但是我如何使它无头运行?

def checkout(browser, url):
browser.get(url)
browserThread1 = threading.Thread(target = checkout, args = (webdriver.Chrome(), 'https://www.google.com'))
browserThread2 = threading.Thread(target = checkout, args = (webdriver.Chrome(), 'https://www.google.com'))
browserThread3 = threading.Thread(target = checkout, args = (webdriver.Chrome(), 'https://www.google.com'))
browserThread4 = threading.Thread(target = checkout, args = (webdriver.Chrome(), 'https://www.google.com'))
browserThread1.start()
browserThread2.start()
browserThread3.start()
browserThread4.start()

你可以创建Chrome选项并将其添加到你想在headless模式下运行的线程。

import threading
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def checkout(browser, url):
browser.get(url)
options = Options()
options.headless = True
browserThread1 = threading.Thread(target = checkout, args = (webdriver.Chrome(options=options), 'https://www.google.com'))
browserThread2 = threading.Thread(target = checkout, args = (webdriver.Chrome(options=options), 'https://www.google.com'))
browserThread3 = threading.Thread(target = checkout, args = (webdriver.Chrome(options=options), 'https://www.google.com'))
browserThread4 = threading.Thread(target = checkout, args = (webdriver.Chrome(options=options), 'https://www.google.com'))
browserThread1.start()
browserThread2.start()
browserThread3.start()
browserThread4.start()

最新更新