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.pyindex 03024af4c..323f55f8d 100644--- a/scrapy/shell.py+++ b/scrapy/shell.py@@ -6,13 +6,14 @@ See documentation in docs/topics/shell.rstfrom __future__ import print_functionimport signal+import warningsfrom twisted.internet import reactor, threads, deferfrom twisted.python import threadablefrom w3lib.url import any_to_urifrom scrapy.crawler import Crawler-from scrapy.exceptions import IgnoreRequest+from scrapy.exceptions import IgnoreRequest, ScrapyDeprecationWarningfrom scrapy.http import Request, Responsefrom scrapy.item import BaseItemfrom scrapy.settings import Settings@@ -98,6 +99,7 @@ class Shell(object):self.vars['spider'] = spiderself.vars['request'] = requestself.vars['response'] = response+ self.vars['sel'] = _SelectorProxy(response)if self.inthread:self.vars['fetch'] = self.fetchself.vars['view'] = open_in_browser@@ -155,3 +157,15 @@ def _request_deferred(request):request.callback, request.errback = d.callback, d.errbackreturn 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)