运行此简单代码时,会打开一个空白页面,其中在 url 中写入“data:,”。 Chrome 驱动程序是正确的版本 (ChromeDriver 81.0.4044.69) 并且与我的 GoogleChrome 版本 (81.0.4044.122) 匹配。 Selenium 也更新了 (3.141.0)
我还将驱动程序的文件夹添加到系统的 PATH 中。 还尝试在 url 中使用 http 而不是 https。
from selenium import webdriver
class GoogleBot:
def __init__(self):
self.driver = webdriver.Chrome(executable_path="C:\Drivers\chromedriver.exe")
driver.get("https://www.google.es/")
GoogleBot()
最佳答案
在您的代码中,您使用了 driver
而不是 self.driver
。请引用以下代码解决您的问题::
from selenium import webdriver
class GoogleBot:
def __init__(self):
self.driver = webdriver.Chrome(executable_path=r"path for chromedriver.exe")
def googleTest(self):
self.driver.get("https://www.google.es/")
self.driver.close()
if __name__ == "__main__":
GoogleBot = GoogleBot()
GoogleBot.googleTest()
关于Python:Selenium Chrome 驱动程序打开空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61437020/