Skip to content

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

Only instantiate XPath selectors if the response is of the proper type. Closes #285

Pablo Hoffman5c18f02adee5
diff --git a/scrapy/shell.py b/scrapy/shell.py
index 5c245bbe3..ba48ae577 100644
--- a/scrapy/shell.py
+++ b/scrapy/shell.py
@@ -17,7 +17,7 @@ from scrapy.utils.response import open_in_browser
from scrapy.utils.url import any_to_uri
from scrapy.utils.console import start_python_console
from scrapy.settings import Settings
-from scrapy.http import Request, Response, TextResponse
+from scrapy.http import Request, Response, HtmlResponse, XmlResponse
class Shell(object):
@@ -80,8 +80,9 @@ class Shell(object):
self.vars['item'] = item
self.vars['settings'] = self.crawler.settings
if url:
- if isinstance(response, TextResponse):
+ if isinstance(response, XmlResponse):
self.vars['xxs'] = XmlXPathSelector(response)
+ if isinstance(response, HtmlResponse):
self.vars['hxs'] = HtmlXPathSelector(response)
self.vars['response'] = response
self.vars['request'] = request