With lxml.html, how do I access single elements without using a for loop?
This is the HTML:
<tr class="headlineRow">
<td>
<span class="headline">This is some awesome text</span>
</td>
</tr>
For example, this will fail with IndexError:
for row in doc.cssselect('tr.headlineRow'):
headline = row.cssselect('td span.headline')
print headline[0]
This will pass:
for row in doc.cssselect('tr.headlineRow'):
headline = row.cssselect('td span.headline')
for first_thing in headline:
print headline[0].text_content()