how can i parse html with lxml
<p>I have this html:</p>

<pre><code>&lt;td class="name-td alLeft bordR"&gt;13.10.2016, Thu&lt;span class="sp"&gt;|&lt;/span&gt;17:00&lt;/td&gt;
</code></pre>

<p>I want to get a date (13.10.2016) and a time (17:00).</p>

<p>I'm doing that:</p>

<pre><code>t = lxml.html.parse(url)
nextMatchDate = t.findall(".//td[@class='bordR']")[count].text
</code></pre>

<p>But getting an error, </p>

<pre><code>IndexError: list index out of range
</code></pre>

<p>I think it happens because I have a html-tags in <code>a</code> tag</p>

<p>Could you help me please?</p>

<p>The problem is in the way you check for the <code>bordR</code> class. <code>class</code> is a <em>multi-valued</em> space-delimited attribute and you have to account for other classes on an element. In XPath you should be using "contains":</p>

<pre><code>.//td[contains(@class, 'bordR')]
</code></pre>

<p>Or, even more reliable would be to <a href="http://stackoverflow.com/a/1604480/771848">add "concat" to the partial match check</a>.</p>

<p>Once you've located the element you can use <code>.text_content()</code> method to get the complete text including all the children:</p>

<pre><code>In [1]: from lxml.html import fromstring

In [2]: data = '&lt;td class="name-td alLeft bordR"&gt;13.10.2016, Thu&lt;span class="sp"&gt;|&lt;/span&gt;17:00&lt;/td&gt;'

In [3]: td = fromstring(data)

In [4]: print(td.text_content())
13.10.2016, Thu|17:00
</code></pre>

<p>To take a step further, you can <a href="https://docs.python.org/2/library/datetime.html#datetime.datetime.strptime" rel="nofollow">load the date string into a <code>datetime</code> object</a>:</p>

<pre><code>In [5]: from datetime import datetime
In [6]: datetime.strptime(td.text_content(), "%d.%m.%Y, %a|%H:%M")
Out[6]: datetime.datetime(2016, 10, 13, 17, 0)
</code></pre>

python html parsing