Merge pull request #675 from ncp1113/patch-1

for loops have to have a : at the end of the line
This commit is contained in:
Mikhail Korobov 2014-04-24 22:48:16 +06:00
commit a96a21e4c6
1 changed files with 3 additions and 3 deletions

View File

@ -222,17 +222,17 @@ At first, you may be tempted to use the following approach, which is wrong, as
it actually extracts all ``<p>`` elements from the document, not only those it actually extracts all ``<p>`` elements from the document, not only those
inside ``<div>`` elements:: inside ``<div>`` elements::
>>> for p in divs.xpath('//p') # this is wrong - gets all <p> from the whole document >>> for p in divs.xpath('//p'): # this is wrong - gets all <p> from the whole document
>>> print p.extract() >>> print p.extract()
This is the proper way to do it (note the dot prefixing the ``.//p`` XPath):: This is the proper way to do it (note the dot prefixing the ``.//p`` XPath)::
>>> for p in divs.xpath('.//p') # extracts all <p> inside >>> for p in divs.xpath('.//p'): # extracts all <p> inside
>>> print p.extract() >>> print p.extract()
Another common case would be to extract all direct ``<p>`` children:: Another common case would be to extract all direct ``<p>`` children::
>>> for p in divs.xpath('p') >>> for p in divs.xpath('p'):
>>> print p.extract() >>> print p.extract()
For more details about relative XPaths see the `Location Paths`_ section in the For more details about relative XPaths see the `Location Paths`_ section in the