首页 > 解决方案 > Python Selenium 在后台不工作

问题描述

当我使用默认(打开浏览器并执行)运行我的代码时,代码工作但当它尝试运行具有后台结果的代码时什么都没有

from datetime import datetime
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
import datetime
import selenium as se
options = se.webdriver.ChromeOptions()

# options.add_argument('--no-sandbox')
# options.add_argument('headless')

driver = se.webdriver.Chrome('c://chromedriver.exe',chrome_options=options)
options.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"')
driver.get('website.com')
time.sleep(2)

当我取消注释时

 # options.add_argument('--no-sandbox')
# options.add_argument('headless')

这一行在后台不工作的情况下运行代码,

数据是实时数据,类似于币安数据每 1 分钟更改一次。

标签: pythonpython-3.xseleniumselenium-webdriverselenium-chromedriver

解决方案


推荐阅读