Parsovanie tabulky miest pre vianocny kamion
HTML
<div id="result">
<pre></pre>
</div>
<table id="cities-table" class="progR">
<tbody>
<tr style="cursor: pointer;">
<th width="15%">29. 11. 2014</th>
<td width="15%">16.00-18.00</td>
<td width="20%"><strong>Říčany u Prahy</strong></td>
<td width="40%">Lidl, Černokostelecká *</td>
</tr>
<tr style="cursor: pointer">
<th>30. 11. 2014</th>
<td>16.00-18.00</td>
<td>Praha 11</td>
<td>Lidl, Opatovská *</td>
</tr>
<tr style="cursor: pointer">
<th>1. 12. 2014</th>
<td>16.00-18.00</td>
<td>Nové Město na Moravě</td>
<td>Vratislavovo náměstí</td>
</tr>
<tr style="cursor: pointer">
<th>1. 12. 2014</th>
<td>16.00-18.00</td>
<td>Ústí nad Labem</td>
<td>Lidl, Všebořická *</td>
</tr>
<tr style="cursor: pointer">
<th>1. 12. 2014</th>
<td>16.00-18.00</td>
<td>Brno Lesná</td>
<td>Lidl, Okružní *</td>
</tr>
<tr style="cursor: pointer">
<th>2. 12. 2014</th>
<td>16.00-18.00</td>
<td>Telč</td>
<td>Na Sádkách</td>
</tr>
<tr style="cursor: pointer">
<th>2. 12. 2014</th>
<td>16.00-18.00</td>
<td>Plzeň</td>
<td>Lidl, Vejprnická *</td>
</tr>
<tr style="cursor: pointer">
<th>2. 12. 2014</th>
<td>16.00-18.00</td>
<td>Olomouc</td>
<td>Lidl, Velkomoravská *</td>
</tr>
<tr style="cursor: pointer">
<th>3. 12. 2014</th>
<td>16.00-18.00</td>
<td>Sušice</td>
<td>náměstí Svobody</td>
</tr>
<tr style="cursor: pointer">
<th>3. 12. 2014</th>
<td>16.00-18.00</td>
<td>České Budějovice</td>
<td>Lidl, Boženy Němcové *</td>
</tr>
<tr style="cursor: pointer">
<th>3. 12. 2014</th>
<td>16.00-18.00</td>
<td>Ostrava</td>
<td>Lidl, U Stadiónu *</td>
</tr>
<tr style="cursor: pointer">
<th>4. 12. 2014</th>
<td>16.00-18.00</td>
...
CSS
table {
display: none;
}
JavaScript
var tableRows = $('table tbody tr');
$.each(tableRows, function(i, e) {
var TDs = $(e).find('td, th');
var datum = $(TDs[0]).text();
var time = $(TDs[1]).text();
var city = $(TDs[2]).text();
var place = $(TDs[3]).text();
var timeList = time.split('-');
var next = datum.replace(/ /g, '') + ' ' + timeList[1].replace('.', ':') + ':00';
place = place.replace('*', '').trim();
var result = '';
result = 'array(' + "\n\t";
result += '"date"=>array("' + datum + '", "' + timeList[0] + '", "' + timeList[1] + '"),' + "\n\t";
result += '"name"=>"' + place + '",' + "\n\t";
result += '"city"=>"' + city + '",' + "\n\t";
result += '"pos"=>array(),' + "\n\t";
result += '"url"=>"",' + "\n\t";
result += '"next"=>"' + next + '",' + "\n\t";
result += '"short_name"=>array("' + city + '","' + place + '")' + "\n";
result += '),';
// result += "\n---------------------------------------------------------\n";
$('#result pre').text($('#result').text() + result)
});
$('#result pre').text($('#result pre').text().trim());