title: How check if element exist in lxml xpath?
body: <p>I use <code>lxml xpath</code> for parsing HTML page in Python 3.</p>
  
  <p>As sample I have code, that finds element HTML: </p>
  
  <pre><code>version_android  = doc.xpath("//div[@itemprop='operatingSystems']//text()")
  </code></pre>
  
  <p>Father I have insert Mysql query:</p>
  
  <pre><code>insert = ("insert into tracks (version) values ('%s')" % (version_android[0]))
  </code></pre>
  
  <p>Problem is, that if is not element in HTML DOM, therefore I get Mysql error when I try to get parsed result in line: <code>version[0]</code> and put in query.</p>
  
  <p>Sometimes result array does not have index <code>version_android[0]</code>, but has index <code>version_android[2]</code>: It makes error in insert function Mysql.</p>
  
  <p>How can I validate this correct? I have a lot the same rules for parsing.</p>
  
  <p>I tried this, but I dislike this solution:</p>
  
  <pre><code>version_android = doc.xpath("//div[@itemprop='operatingSystems']//text()")
          if len(version_android):
              version_android = version_android[0]
          else:
              version_android = ""
  </code></pre>