<tr>
<td><span style="white-space:nowrap">Aug 29, 2016 06:05</span></td>
<td><a class="A" title="B" href="C">
<td>....
....
</tr>
I have many < td> elements wrapped in < tr> elements among the html I want to access every single text within the first < td> element in its < tr> wrap and every single href for the second < td> element.
Should probably use 2 different queries for each.
char = tree.xpath('//tr/td[2]/@href')
this is what I came up with for the href query but wouldn't do the work for me.
Update
thanks to help from lauda I got in the right track
This is what worked out for me
first = tree.xpath('//tr/td/span/text()')
second = tree.xpath('//tr/td[2]/a/@href')
The text is not directly in the td
, for the first you could use something like:
//tr/td/span
for the second:
//tr/td/a
or if you want the href and not the element then:
//tr/td/a/@href
thanks a lot that lead me to the right direction
date = tree.xpath('//tr/td/span/text()') hrefs = tree.xpath('//tr/td[2]/a/@href')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.