Having the following:
from lxml import html
import io
from lxml import etree
parser = etree.HTMLParser()
doc = etree.parse(io.FileIO("index.html"), parser)
i=1
total = []
aa = doc.xpath(".//body/table[10]")
for x in aa:
for j in x:
for k in j:
print type(k) #output is <type 'lxml.etree._Element'>
print k.text
Part of html file:
This will display:
/Request_number_1
15
0
100.00%
1035 ms
923 ms
1407 ms
None
/Request_number_2
15
0
100.00%
966 ms
857 ms
1613 ms
None
How can I iterate trough this lxml element? I want to retrieve the first value expressed in milliseconds (ex. average_time_array = [1035 ms, 966ms])
How about using this xpath expression? .//body/table[1]/tr/td[5]
average_time_array = [td.text for td in doc.xpath(".//body/table[10]/tr/td[5]")]
print average_time_array
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.