html - Python Scrapy - XPath for nested table tags -


this source code:

<table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td align="center"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td style="border-left: 1px solid rgb(153, 153, 153); border-right: 1px solid rgb(153, 153, 153);"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <tr> <td height="511"> <table width="100%" cellspacing="0" cellpadding="5" border="0" height="500"> <tbody> <tr> <td width="1%" valign="top" height="500"> <table width="100%" cellspacing="1" cellpadding="1" bordercolor="#cccccc" border="0" bgcolor="#ffffff" align="center"> <tbody> <tr bgcolor="#bb375f" bordercolor="#cccccc"> 

how write xpath reach innermost <tr> tag?

here's i've tried:

top_table = response.xpath("//table[4]/tbody/tr/td") content_table = top_table.xpath("table") print content_table 

and output i'm getting:

[ < selector xpath='table' data=u' < table width="100%" border="0" cellspaci' > ]

basically i'm able penultimate table in first line , innermost table want reach. not sure how proceed or i'm going wrong? or suggestions welcome. thanks!

basically i'm able penultimate table in first line , innermost table want reach.

one possible way inner-most table making sure candidate table doesn't have descendant table element :

//table[not(.//table)] 

so suggest try tr/td inner-most table :

top_table = response.xpath("//table[not(.//table)]/tbody/tr/td") 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -