English 中文(简体)
甲型六氯环己烷
原标题:Python Selenium Detach Option Not Working

I want to write a Python script using Selenium and Chrome where Selenium won t close the Chrome browser when the script finishes. From doing a bunch of googling, it looks like the standard solution is to use the detach option. But when I run the following script:

import selenium
from selenium import webdriver

from selenium.webdriver.chrome.options import Options
chrome_options = Options() 
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.google.com/")

它打开了 Chrome,进入谷歌主页,然后关闭浏览器。 它不犯任何错误。

它为什么不发挥作用? I m使用最新版本的谷歌 Chrome窗10, 而I ve是安装的 se模块的最新版本。 我在网上找不到任何东西,说实验性脱节选择不再存在。 我对进行了双重检查。

最佳回答

该守则对我来说是完美的:selenium-wire,希望它能为你们工作。

from seleniumwire import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
driver.get("https://www.google.com/")
问题回答

我发现了另一条路要走: Chrome在遥远的脱浮模式下开端,然后与它连接起来。 这样,不仅使浏览器保持开放,而且你也可以利用现有的 Chrome光,使你能够利用贵方的 co点,使你能够进入,而不必在你管理该书的每一个时间进行记录。

如果您重新登上Windows 10,你需要做些什么:

  1. Start Google Chrome up remotely, pointed towards your existing user profile and the port you want to use:
cd "C:Program Files (x86)GoogleChromeApplication"
chrome.exe -remote-debugging-port=9014 --user-data-dir="%LOCALAPPDATA%GoogleChromeUser Data"
  1. In your python script, connect to the local port that this version of Chrome is running on:
import selenium
from selenium import webdriver

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "localhost:9014")
driver = webdriver.Chrome(options=chrome_options)

driver.get("https://github.com/")

www.un.org/Depts/DGACM/index_spanish.htm 该法典现在运作良好:。

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

r_options = Options()
r_options.add_experimental_option( detach , True)
driver = webdriver.Chrome(options=r_options)

您是否使用<>Pycharm? 在窗户平分的指挥线终端中,没有这个问题。

options.add_experimental_option("detach", True)
# remember don t call driver.quit()

与Pycharm公司一道,Browser在文字结束后关闭了2-5秒。 但这并不是因为每个选择。

如果你打下了真心,不叫司机,则行凶者不会被rom笑。

如果该办法也已经结束,可尝试:

options.add_experimental_option( excludeSwitches , [ enable-logging ])

This option will disable the info in the script terminal like:

DevTools listening on ws://127.0.0.1:9512/devtools/browser/ed13e40d-2fa3-47ea-ae63-a2975f282b85

我猜测,如果我们的文字结束,Browser的排他性可能会转向我们的文字终点站, 药房关闭了码头,因此浏览器的输出将失败,而灭亡。

“在此处的影像描述”/</a





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签