s = """
<tbody>
<tr>
<td style="border-bottom: none">
<span class="graytext" style="font-weight: bold;"> Reply #3 - </span>
<span class="graytext" style="font-size: 11px">
05/13/09 2:02am
<br>
</span>
</td>
</tr>
</tbody>
"""
In the HTML string I need to take out the date string.
I tried in this way
import lxml
doc = lxml.html.fromstring(s)
doc.xpath('//span[@class="graytext" and @style="font-size: 11px"]')
But this is not working. I should have to take only the Datestring.
Your query is selecting the
span, you need to grab the text from it:Most queries return a sequence, I normally use a helper function that gets the first item.
Then: