From 1ca489de923b6aeb8beb202777f4c3651bd487e1 Mon Sep 17 00:00:00 2001 From: Elias Dorneles Date: Wed, 23 Jul 2014 20:42:36 -0300 Subject: [PATCH] removes weird indentation in the shell results --- docs/topics/selectors.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/topics/selectors.rst b/docs/topics/selectors.rst index a08477e3435..d966a67d2c1 100644 --- a/docs/topics/selectors.rst +++ b/docs/topics/selectors.rst @@ -439,26 +439,26 @@ Example:: Converting a *node-set* to string:: >>> sel.xpath('//a//text()').extract() # take a peek at the node-set - [u'Click here to go to the ', u'Next Page'] + [u'Click here to go to the ', u'Next Page'] >>> sel.xpath("string(//a[1]//text())").extract() # convert it to string - [u'Click here to go to the '] + [u'Click here to go to the '] A *node* converted to a string, however, puts together the text of itself plus of all its descendants:: >>> sel.xpath("//a[1]").extract() # select the first node - [u'Click here to go to the Next Page'] + [u'Click here to go to the Next Page'] >>> sel.xpath("string(//a[1])").extract() # convert it to string - [u'Click here to go to the Next Page'] + [u'Click here to go to the Next Page'] So, using the ``.//text()`` node-set won't select anything in this case:: >>> sel.xpath("//a[contains(.//text(), 'Next Page')]").extract() - [] + [] But using the ``.`` to mean the node, works:: >>> sel.xpath("//a[contains(., 'Next Page')]").extract() - [u'Click here to go to the Next Page'] + [u'Click here to go to the Next Page'] .. _`XPath string function`: http://www.w3.org/TR/xpath/#section-String-Functions @@ -524,7 +524,7 @@ you can just select by class using CSS and then switch to XPath when needed:: >>> from scrapy import Selector >>> sel = Selector(text='
') >>> sel.css('.shout').xpath('./time/@datetime').extract() - [u'2014-07-23 19:00'] + [u'2014-07-23 19:00'] This is cleaner than using the verbose XPath trick shown above. Just remember to use the ``.`` in the XPath expressions that will follow.