I am working on lxml for fetching the html page.
I want to fetch the html table which have the class name as ‘class1’.
I have done something like this :
for span in doc.xpath('//table[@class="class1"]'):
print span
But,
after this I found that there are 4 tables in HTML page which have class name as ‘class1’.
for example :
table A
table B
table C
table D
these all 4 tables have the same class name.
how I can fetch only table B?
You can just get the second item of list:
result = doc.xpath('//table[@class="class1"]') if len(result) > 1: print result[1]Or if your table has id, you can get it via xpath:
print doc.xpath('//table[@id="you id"]')[0]