title: Python XPath SyntaxError: invalid predicate
body: <p>i am trying to parse an xml like</p>
  
  <pre><code>&lt;document&gt;
      &lt;pages&gt;
  
      &lt;page&gt;   
         &lt;paragraph&gt;XBV&lt;/paragraph&gt;
  
         &lt;paragraph&gt;GHF&lt;/paragraph&gt;
      &lt;/page&gt;
  
      &lt;page&gt;
         &lt;paragraph&gt;ash&lt;/paragraph&gt;
  
         &lt;paragraph&gt;lplp&lt;/paragraph&gt;
      &lt;/page&gt;
  
      &lt;/pages&gt;
  &lt;/document&gt;
  </code></pre>
  
  <p>and here is my code</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  
  tree = ET.parse("../../xml/test.xml")
  
  root = tree.getroot()
  
  path="./pages/page/paragraph[text()='GHF']"
  
  print root.findall(path)
  </code></pre>
  
  <p>but i get an error</p>
  
  <pre><code>print root.findall(path)
    File "X:\Anaconda2\lib\xml\etree\ElementTree.py", line 390, in findall
      return ElementPath.findall(self, path, namespaces)
    File "X:\Anaconda2\lib\xml\etree\ElementPath.py", line 293, in findall
      return list(iterfind(elem, path, namespaces))
    File "X:\Anaconda2\lib\xml\etree\ElementPath.py", line 263, in iterfind
      selector.append(ops[token[0]](next, token))
    File "X:\Anaconda2\lib\xml\etree\ElementPath.py", line 224, in prepare_predicate
      raise SyntaxError("invalid predicate")
  SyntaxError: invalid predicate
  </code></pre>
  
  <p>what is wrong with my xpath?</p>
  
  <p><strong>Follow up</strong></p>
  
  <p>Thanks falsetru, your solution worked. I have a follow up. Now, i want to get all the paragraph elements that come before the paragraph with text <code>GHF</code>. So in this case i only need the <code>XBV</code> element. I want to ignore the <code>ash</code> and <code>lplp</code>. i guess one way to do this would be </p>
  
  <pre><code>result = []
  for para in root.findall('./pages/page/'):
      t = para.text.encode("utf-8", "ignore")
      if t == "GHF":
         break
      else:
          result.append(para)
  </code></pre>
  
  <p>but is there a better way to do this?</p>