Reputation: 39
My webpage Contains 8 Tables. I Want Parse the 3rd Table
Page Source for my 1st, 3rd, 5th & 7th Table: (All Contains 80 Elements)
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable">
Page Source for my 2nd, 4th, 6th, 8th Table: (Elements vary according to the match)
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable noBorderTop">
So I Parsed like this:
$name = $html->find('div[class=cricket-accorContent] table[class=cricket-performanceTable] td');
It working upto first table ($name[80]).
If I Print ($name[81]) It Displaying 2nd Table's first Element. But I want to Print 3rd Table's 1st Element
Eventhough table[class= ]
is different. 1st Table table[class=cricket-performanceTable]
for Second Table: table[class=cricket-performanceTable noBorderTop]
How Can I Parse the Third Table?
Upvotes: 1
Views: 813
Reputation: 176
try this:
$src = '<div class="cricket-accorContent">
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable"><tr><td>11</td><td>12</td></tr></table>
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable noBorderTop"><tr><td>21</td><td>22</td></tr></table>
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable"><tr><td>31</td><td>32</td></tr></table>
<table cellpadding="0" cellspacing="0" width="100%" border="0" class="cricket-performanceTable noBorderTop"><tr><td>41</td><td>42</td></tr></table>
</div>
';
$html = str_get_html($src);
$thirdTable = $html->find('div[class=cricket-accorContent] table', 2);
$firstTD = $thirdTable->find('td', 0)->plaintext;
$secondTD = $thirdTable->find('td', 1)->plaintext;
echo '-' . $firstTD . '-';
echo '-' . $secondTD . '-';
Outputs:
-31--32-
Upvotes: 3