Scrapy, a fast high-level web crawling & scraping framework for Python.
port scrapy shell to unified selector api
Daniel Grañaa9eb0b74c8ae
diff --git a/scrapy/shell.py b/scrapy/shell.pyindex 642b3d6e6..8b6c209cb 100644--- a/scrapy/shell.py+++ b/scrapy/shell.py@@ -11,7 +11,7 @@ from w3lib.url import any_to_urifrom scrapy.item import BaseItemfrom scrapy.spider import BaseSpider-from scrapy.selector import XPathSelector, XmlXPathSelector, HtmlXPathSelector, XmlCSSSelector, HtmlCSSSelector+from scrapy.selector import Selectorfrom scrapy.utils.spider import create_spider_for_requestfrom scrapy.utils.misc import load_objectfrom scrapy.utils.response import open_in_browser@@ -24,7 +24,7 @@ from scrapy.exceptions import IgnoreRequestclass Shell(object):relevant_classes = (BaseSpider, Request, Response, BaseItem,- XPathSelector, Settings)+ Selector, Settings)def __init__(self, crawler, update_vars=None, code=None):self.crawler = crawler@@ -95,14 +95,7 @@ class Shell(object):self.vars['spider'] = spiderself.vars['request'] = requestself.vars['response'] = response- self.vars['xxs'] = XmlXPathSelector(response) \- if isinstance(response, XmlResponse) else None- self.vars['xcs'] = XmlCSSSelector(response) \- if isinstance(response, XmlResponse) else None- self.vars['hxs'] = HtmlXPathSelector(response) \- if isinstance(response, HtmlResponse) else None- self.vars['hcs'] = HtmlCSSSelector(response) \- if isinstance(response, HtmlResponse) else None+ self.vars['ss'] = Selector(response)if self.inthread:self.vars['fetch'] = self.fetchself.vars['view'] = open_in_browserdiff --git a/scrapy/tests/test_command_shell.py b/scrapy/tests/test_command_shell.pyindex bdfd8bb20..8dbaa632f 100644--- a/scrapy/tests/test_command_shell.py+++ b/scrapy/tests/test_command_shell.py@@ -31,7 +31,7 @@ class ShellTest(ProcessTest, SiteTest, unittest.TestCase):@defer.inlineCallbacksdef test_response_selector_html(self):- xpath = 'hxs.select("//p[@class=\'one\']/text()").extract()[0]'+ xpath = 'ss.xpath("//p[@class=\'one\']/text()").extract()[0]'_, out, _ = yield self.execute([self.url('/html'), '-c', xpath])self.assertEqual(out.strip(), 'Works')