Python Selenium无头线程

2024-05-28 22:31:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个Python Selenium线程脚本,但如何让它无头运行

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()

Tags: httpsbrowsercomurltargetwwwgoogleargs
1条回答
网友
1楼 · 发布于 2024-05-28 22:31:57

您可以创建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()

相关问题 更多 >

    热门问题