python报错问题

pycharm问题
问题是在执行以下代码:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_service = Service(executable_path=ChromeDriverManager().install())
webdriver.Chrome(service=chrome_service)
input()

出现报错如图:

img

driver.get()输入一下你的url试试:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=chrome_service)
driver.get("https://www.baidu.com")

input()

如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

【以下回答由 GPT 生成】

这个报错是因为在使用Selenium时,没有指定Chrome浏览器的路径。为了解决这个问题,你可以按照以下步骤操作:

  1. 确保你已经安装了Chrome浏览器,并且下载了对应版本的ChromeDriver。
  2. 在代码中,你可以使用ChromeDriverManager来自动安装和管理ChromeDriver,这样你就不需要手动指定ChromeDriver的路径。

以下是修改后的代码示例:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_service = Service(executable_path=ChromeDriverManager().install())
webdriver.Chrome(service=chrome_service)
input()

请尝试使用修改后的代码,如果还有其他问题,请提供具体的报错信息和其他可能有关的代码片段。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^