我想提取下列表格內容並通過pandas將其保存在一個CSV文件中,但僅提取日期(例如Thu,11/02)和所有值,這些值由€ /兆瓦時。非常感謝你提前。通過Python獲取html表格內容
的源代碼:
<table cellspacing="0" cellpadding="0" border="0" class="list hours responsive" width="100%">
<tbody>
<tr>
<th class="title"></th>
<th class="units"></th>
<th>Thu, 11/02</th>
<th>Fri, 12/02</th>
<th>Sat, 13/02</th>
<th>Sun, 14/02</th>
<th>Mon, 15/02</th>
<th>Tue, 16/02</th>
<th>Wed, 17/02</th>
</tr>
<tr class="no-border">
<td class="title">
00 - 01
</td>
<td>€/MWh</td>
<td>23.82</td>
<td>22.81</td>
<td>22.23</td>
<td>13.06</td>
<td>16.57</td>
<td>25.99</td>
<td>32.45</td>
</tr>
<tr>
<td> </td>
<td>MWh</td>
<td>10,266.0</td>
<td>9,626.6</td>
<td>12,255.9</td>
<td>11,084.7</td>
<td>11,039.5</td>
<td>13,134.7</td>
<td>9,958.1</td>
</tr>
<tr class="no-border">
<td class="title">
01 - 02
</td>
<td>€/MWh</td>
<td>21.48</td>
<td>21.59</td>
<td>21.10</td>
<td>12.17</td>
<td>16.00</td>
<td>23.65</td>
<td>31.27</td>
</tr>
<tr>
<td> </td>
<td>MWh</td>
<td>9,843.3</td>
<td>9,494.4</td>
<td>11,823.3</td>
<td>10,531.9</td>
<td>9,970.5</td>
<td>12,875.6</td>
<td>9,958.8</td>
</tr>
<tr class="no-border">
<td class="title">
02 - 03
</td>
<td>€/MWh</td>
<td>21.00</td>
<td>21.30</td>
<td>20.21</td>
<td>8.81</td>
<td>14.55</td>
<td>22.91</td>
<td>29.72</td>
</tr>
<tr>
<td> </td>
<td>MWh</td>
<td>9,857.0</td>
<td>9,427.9</td>
<td>11,755.2</td>
<td>10,061.9</td>
<td>9,881.7</td>
<td>12,841.0</td>
<td>9,896.9</td>
</tr>
<tr class="no-border">
<td class="title">
03 - 04
</td>
<td>€/MWh</td>
<td>19.94</td>
<td>19.86</td>
<td>19.94</td>
<td>6.74</td>
<td>13.14</td>
<td>22.04</td>
<td>27.44</td>
</tr>
<tr>
<td> </td>
<td>MWh</td>
<td>9,486.2</td>
<td>10,492.7</td>
<td>12,609.1</td>
<td>11,216.6</td>
<td>10,199.9</td>
<td>11,209.7</td>
<td>9,698.5</td>
</tr>
</tbody>
請[編輯]你的問題,1)改善你的HTML的縮進2)添加你已經嘗試了Python代碼。 –
http://stackoverflow.com/questions/11790535/extracting-data-from-html-table – CodeMonkey