Skip to content

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

Restore and deprecate "sel" shortcut

Daniel Graña1e7ddc8e5206
diff --git a/scrapy/shell.py b/scrapy/shell.py
index 03024af4c..323f55f8d 100644
--- a/scrapy/shell.py
+++ b/scrapy/shell.py
@@ -6,13 +6,14 @@ See documentation in docs/topics/shell.rst
from __future__ import print_function
import signal
+import warnings
from twisted.internet import reactor, threads, defer
from twisted.python import threadable
from w3lib.url import any_to_uri
from scrapy.crawler import Crawler
-from scrapy.exceptions import IgnoreRequest
+from scrapy.exceptions import IgnoreRequest, ScrapyDeprecationWarning
from scrapy.http import Request, Response
from scrapy.item import BaseItem
from scrapy.settings import Settings
@@ -98,6 +99,7 @@ class Shell(object):
self.vars['spider'] = spider
self.vars['request'] = request
self.vars['response'] = response
+ self.vars['sel'] = _SelectorProxy(response)
if self.inthread:
self.vars['fetch'] = self.fetch
self.vars['view'] = open_in_browser
@@ -155,3 +157,15 @@ def _request_deferred(request):
request.callback, request.errback = d.callback, d.errback
return d
+
+
+class _SelectorProxy(object):
+
+ def __init__(self, response):
+ self._proxiedresponse = response
+
+ def __getattr__(self, name):
+ warnings.warn('"sel" shortcut is deprecated. Use "response.xpath()", '
+ '"response.css()" or "response.selector" instead',
+ category=ScrapyDeprecationWarning, stacklevel=2)
+ return getattr(self._proxiedresponse.selector, name)