I'm scraping information from a website. I am trying to get the following information from the two tables.
PlayerRank PlayerName Prizes
The information in both tables are correlated.
I then need to enter the information for each player into my database.
I'm stuck right now trying to get the information from both tables into 1 array.
I created a JSFiddle to try different things http://jsfiddle.net/drycsLjk/4/
Table One
<table>
<thead>
<tr>
<th>Rank</th>
<th>Prizes</th>
<th>Additional Prizes</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>1</td>
<td>$2.5</td>
<td>N/A</td>
</tr>
<tr class="odd">
<td>2</td>
<td>$1.5</td>
<td>N/A</td>
</tr>
<tr class="even">
<td>3</td>
<td>$1</td>
<td>N/A</td>
</tr>
<tr class="odd">
<td>4</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="even">
<td>5</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="odd">
<td>6</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="even">
<td>7</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="odd">
<td>8</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="even">
<td>9</td>
<td>$0</td>
<td>N/A</td>
</tr>
<tr class="odd">
<td>10</td>
<td>$0</td>
<td>N/A</td>
</tr>
</tbody>
</table>
Table Two
<table id="ranked_players">
<thead>
<tr><th>RANK</th>
<th>NAME</th>
<th>CHIPS</th>
</tr></thead>
<tbody>
<tr class="odd">
<td>1</td>
<td>shanghai</td>
<td>20000.00</td>
</tr>
<tr class="even">
<td>2</td>
<td>SOCRATES</td>
<td>0.00</td>
</tr>
<tr class="odd">
<td>3</td>
<td>mollypop</td>
<td>0.00</td>
</tr>
<tr class="even">
<td>4</td>
<td>Vegaz</td>
<td>0.00</td>
</tr>
<tr class="odd">
<td>5</td>
<td>aRrOwDreWLs</td>
<td>0.00</td>
</tr>
<tr class="even">
<td>6</td>
<td>Cheatos</td>
<td>0.00</td>
</tr>
<tr class="odd">
<td>7</td>
<td>easypoker</td>
<td>0.00</td>
</tr>
<tr class="even">
<td>8</td>
<td>YNVME</td>
<td>0.00</td>
</tr>
<tr class="odd">
<td>9</td>
<td>askewbowl</td>
<td>0.00</td>
</tr>
<tr class="even">
<td>10</td>
<td>funlv</td>
<td>0.00</td>
</tr>
</tbody>
</table>
The JQuery
$(document).ready(function(){
var columns = $('#ranked_players thead th').map(function() {
return $(this).text();
});
var playerTable = $('#ranked_players tbody tr').map(function(i) {
var row = {};
$(this).find('td').each(function(i) {
var rowName = columns[i];
row[rowName] = $(this).text();
});
return row;
}).get();
console.log(playerTable);
var columns = $('#prize_info_container table thead th').map(function() {
return $(this).text();
});
var prizeTable = $('#prize_info_container table tbody tr').map(function(i) {
var row = {};
$(this).find('td').each(function(i) {
var rowName = columns[i];
row[rowName] = $.trim($(this).text());
});
return row;
}).get();
console.log(prizeTable);
});