Python firefox:';非类型';对象没有属性';退出';
升级Python firefox:';非类型';对象没有属性';退出';,python,selenium,firefox,Python,Selenium,Firefox,升级firefox和selenium后,我遇到了一些代码问题 我对python 代码 错误 #python selenium_scrap.py--查询“test” 回溯(最近一次呼叫最后一次): 文件“selenium_scrape.py”,第48行,在 刮 文件“selenium_scrape.py”,第34行,在uu init中__ 自我错误(str(err)) 文件“selenium_scrape.py”第38行出错 self.close() 文件“selenium_scrape.py”,
firefox
和selenium
后,我遇到了一些代码问题
我对python
代码
错误
#python selenium_scrap.py--查询“test”
回溯(最近一次呼叫最后一次):
文件“selenium_scrape.py”,第48行,在
刮
文件“selenium_scrape.py”,第34行,在uu init中__
自我错误(str(err))
文件“selenium_scrape.py”第38行出错
self.close()
文件“selenium_scrape.py”,第44行,关闭
self.driver.quit()
AttributeError:“非类型”对象没有属性“退出”
事件的顺序似乎是:
error
错误
调用关闭
close
试图调用quit
,但self
(您的驱动程序)的值为None
。。。没有名为“退出”的方法因此,最终的错误可以追溯到。插入两个战略性的
print
命令来跟踪驱动程序是否初始化过(我希望没有)。一个可能的点可能在异常处理程序中的Init driver
下:打印您引发的异常,以及围绕问题的一个或两个有用值。请阅读并遵循帮助文档中的发布指南。适用于这里。在您发布MCVE代码并准确描述问题之前,我们无法有效地帮助您。例如,再现问题是否真的取决于所有这些import
语句?建议:print>>sys.stderr,str
在self.close()之前,以便您可以看到诊断消息。
import sys
import time
import getopt
import urllib
import selenium
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
class Scrape:
display = None
driver = None
def __init__(self):
# Start display
self.display = Display(visible=0, size=(800, 600))
self.display.start()
# Init args
query = ''
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['query=','proxy='])
for opt, arg in opts:
if opt == '--query':
query = arg
except getopt.GetoptError as err:
self.error(str(err))
# Init driver
try:
self.driver = webdriver.Firefox()
self.driver.wait = WebDriverWait(self.driver, 5)
except selenium.common.exceptions.WebDriverException as err:
self.error(str(err))
print('teeeesting...!')
def error(self, str):
self.close()
print>>sys.stderr, str
sys.exit(1)
def close(self):
self.driver.quit()
self.display.stop()
if __name__ == '__main__':
Scrape()
# python selenium_scrape.py --query "test"
Traceback (most recent call last):
File "selenium_scrape.py", line 48, in <module>
Scrape()
File "selenium_scrape.py", line 34, in __init__
self.error(str(err))
File "selenium_scrape.py", line 38, in error
self.close()
File "selenium_scrape.py", line 44, in close
self.driver.quit()
AttributeError: 'NoneType' object has no attribute 'quit'