python-3.x - 试图通过硒关闭便携式浏览器
问题描述
我正在尝试通过 selenium 关闭便携式浏览器
我通过了--remote-debugging-port=9222
,因为如果我不通过它,那么程序就会陷入webdriver.Chrome()
. 它将打开便携式浏览器,但不会加载 URL。
但是在打开 URL 后,我想关闭浏览器,但driver.quit()
它对我不起作用。我已经尝试了一些其他方法来关闭浏览器,但它们也不起作用。
我想关闭由该程序打开的浏览器的特定实例,而不是其他打开的浏览器实例。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.binary_location = 'C:/Portable/GoogleChromePortable/GoogleChromePortable.exe'
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--profile-directory=Person 1")
driver = webdriver.Chrome(options=chrome_options,executable_path='C:/Portabl/chromedriver_win32/chromedriver.exe')
url = "https://www.google.com/"
driver.get(url)
driver.quit()
我在用:
selenium 3.141.0, windows 10, python 3.8.0, portable chrome version 93.0.4577.63 (32-bit)
解决方案
你的这个声明
我通过了 --remote-debugging-port=9222 因为如果我不通过它,那么程序就会卡在 webdriver.Chrome() 的对象创建中
是不正确的。--remote-debugging-port=9222
看起来像是部署应用程序的端口号,并且您已使用 chrome 选项将它们发送到browser object
.
driver.quit()
这通常应该有效,当它不起作用时错误是什么?
另外,要关闭单个实例,您可以这样做
driver.close()
看看是否有帮助。
推荐阅读
- apache-kafka - KafkaConsumer:如何提高日志级别?
- python - 如何导入 txt 文件并在 /t 上创建两列表拆分?
- java - 将json插入postgreSQL
- c# - SQLKata:在 SqlLite 的查询中错误地添加了“”
- amazon-web-services - 在 AWS 上设计具有数据库后端的高可用性 API 服务
- neo4j - Neo4j嵌入式中的逻辑节点删除
- java - LOAD DATA LOCAL INFILE - 无效的 sql 语句
- regex - 忽略来自 Searchword 的字符时进行正则表达式匹配
- java - PostgreSQL 到 Druid 摄取抛出 NullPointerException
- java - Hibernate Search:静态块调用 Version#touch() 的目的是什么