代码如下
from selenium import webdriver
from time import sleep
driver=webdriver.Firefox()
driver.get("http://www.51zxw.net")
print(driver.title)
sleep(3)
driver.get("http://www.baidu.com")
print(driver.title)
sleep(2)
运行报错
C:\Python35\python.exe E:/Python_script/webdriver/open_wyzxw.py
Traceback (most recent call last):
File "E:/Python_script/webdriver/open_wyzxw.py", line 3, in <module>
driver=webdriver.Firefox()
File "C:\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in init
keep_alive=True)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message:
opt = webdriver.FirefoxOptions()
driver = webdriver.Firefox(options=opt)
把对应的火狐driver放置path路径下
driver=webdriver.Firefox() 启动器位置不对 是不是忘记传位置了
– wow2828 6年前@wow2828: 啊,那应该加在哪里呀,我不是很懂,请帮帮忙
– 尚市桃 6年前@尚市桃: https://blog.csdn.net/u011541946/article/details/64129041 看下你是不是忘记下载火狐浏览器的 webdriver插件了
– wow2828 6年前@尚市桃: 你有自学网的视频吗
– wow2828 6年前