“代码是无法到达的”但是代码仍然可以到达(Visual Studio代码)

发布于 2025-01-30 06:42:31 字数 1284 浏览 4 评论 0原文

我有以下代码访问网站并停止浏览器通知:

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

option = webdriver.ChromeOptions()
***option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("detach", True)
option.add_experimental_option("prefs", { 
    "profile.default_content_setting_values.notifications": 2 
})

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get("https://www.reddit.com/r/AskReddit/")

该代码运行,但是我的IDE(Visual Studio Code)表示,从***开始,“代码是无法实现的塔属于”。有人知道我如何解决这个问题吗?这很烦人,因为它在***线之后弄清楚了所有内容。谢谢。

我所看到的视觉表示:

”在此处输入映像说明“

带警告:

“在此处输入图像说明”

I have the following code that accesses a website and stops browser notifications:

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

option = webdriver.ChromeOptions()
***option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("detach", True)
option.add_experimental_option("prefs", { 
    "profile.default_content_setting_values.notifications": 2 
})

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get("https://www.reddit.com/r/AskReddit/")

The code runs, but my IDE (Visual Studio Code) says that from *** onwards the "Code is unreachable Pylance". Does anyone know how I could fix this? It's annoying since it grays out everything after the *** line. Thank you.

Visual representation of what I'm seeing:

enter image description here

With warning:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒲公英的约定 2025-02-06 06:42:31

解决方案:

这是一个错误。更新到最新版本的硒,以解决该问题。

我通过在此处讨论相同的问题来发现这一点: https:// github。 com/microsoft/pylance-release/essume/2807

Solution:

It's a bug. Update to the most recent version of selenium to fix the issue.

I found this out by finding the same issue also being discussed here: https://github.com/microsoft/pylance-release/issues/2807

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文