From 012211accda0fb5ce3af2d4010e2b51db33bdd02 Mon Sep 17 00:00:00 2001 From: Mateusz Golewski Date: Thu, 30 Jan 2014 23:39:15 +0100 Subject: [PATCH] Add docs for extract_first() --- docs/topics/selectors.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/topics/selectors.rst b/docs/topics/selectors.rst index 00ed8152c..0ce0f084e 100644 --- a/docs/topics/selectors.rst +++ b/docs/topics/selectors.rst @@ -139,6 +139,16 @@ method, as follows:: >>> response.xpath('//title/text()').extract() [u'Example website'] +If you want to extract only first matched element, you must call the selector ``.extract_first()`` + + >>> sel.xpath('//ul/li').extract_first() + u'First list element' + +It returns ``None`` if no element was found: + + >>> sel.xpath('//ul/li[999]').extract_first() + None + Notice that CSS selectors can select text or attribute nodes using CSS3 pseudo-elements::