Python 硒壁虎驱动器

Python Selenium Geckodrive

嘿,刚刚尝试使用 Firefox 启动基本浏览器。 我试过使用可执行路径、if 语句,但没有 if 语句,浏览器仍然无法打开。我已经检查了 shell 但我没有 error.My 最好的猜测是我缺少某种动作我只需要有人使用我当前的代码将我指向正确的方向,谢谢。

from selenium import webdriver 

class testbot():
    def botfox(self):
        driver = self.driver = webdriver.firfox(geckodriver)
        driver.get("https://wwww.google.com")

if __name__ == "__botfox__":
    botfox()

如果这有效,我会感到惊讶。您是否尝试过通过 testbot().botfox() 调用它?

webdriver.firfox 不起作用,因为语法是 webdriver.Firefox webdriver.firfox(geckodriver) 不起作用,因为 geckodriver 未在任何地方定义 botfox() 将不起作用,因为没有定义的函数。 testbot 中有一个,但您需要先实例化 class,然后通过 testbot().botfox()

调用它

好的,试试这个:)

from selenium import webdriver 

class testbot():

    def botfox(self):
        self.driver = webdriver.Firefox()
        self.driver.get("https://wwww.google.com")

if __name__ == '__main__':
    testBotInstace = testbot()
    testBotInstace.botfox()