Python壁虎

2024-10-06 12:19:40 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我只是在尝试使用Firefox启动一个基本的浏览器。 我试过使用可执行路径,if语句,如果没有if语句,浏览器仍然无法打开。我检查了弹壳,但没找到错误。我的最好的猜测是我错过了某种行动,我只是需要有人指出我在正确的方向使用我目前的代码,谢谢你。你知道吗

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()

Tags: 代码fromself路径ifdriverselenium错误
2条回答

好的,试试这个:)

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()

如果真能成功我会很惊讶的。你试过通过testbot().botfox()叫它吗?你知道吗

webdriver.firfox不起作用,因为语法是webdriver.Firefoxwebdriver.firfox(geckodriver)不起作用,因为geckodriver在任何地方都没有定义 botfox()将不起作用,因为没有定义这样的函数。在testbot中有一个类,但是您需要首先实例化该类,然后通过testbot().botfox()调用它

相关问题 更多 >