Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

added __nonzero__ method to XPathSelector

Pablo Hoffmanacebe63d0a24
diff --git a/scrapy/trunk/scrapy/xpath/selector.py b/scrapy/trunk/scrapy/xpath/selector.py
index 3902efe27..4709da696 100644
--- a/scrapy/trunk/scrapy/xpath/selector.py
+++ b/scrapy/trunk/scrapy/xpath/selector.py
@@ -84,6 +84,9 @@ class XPathSelector(object):
"""Register namespace so that it can be used in XPath queries"""
self.doc.xpathContext.xpathRegisterNs(prefix, uri)
+ def __nonzero__(self):
+ return bool(self.extract())
+
def __str__(self):
return "<%s (%s) xpath=%s>" % (type(self).__name__, getattr(self.xmlNode, 'name', type(self.xmlNode).__name__), self.expr)