0
我試圖從Excel文件中的鏈接獲得同樣的表,我收到表使用下面如何獲得與合併單元格的表格中完全相同的格式在excel文件
#Getting particular table from the page and sending to excel file
page = urllib2.urlopen('http://developer.android.com/about/dashboards/index.html').read()
soup = BeautifulSoup(page)
a = soup('div', {'class' : 'col-5'})[0]
with open('android version 2013_01_18.csv', 'wb') as csvfile:
csvout = csv.writer(csvfile, delimiter=',')
csvout.writerow(["Version","Codename","API", "Distribution"])
for table in a.findAll('table'):
print '#'
print '# Table'
print '# Fields: ' + ','.join([tr.text for tr in table.findAll('th')])
for row in table.findAll('tr'):
csvout.writerow([tr.text for tr in row.findAll('td')])
代碼
我正在輸出Excel作爲:
1.6 Donut 4 0.20%
2.1 Eclair 7 2.40%
2.2 Froyo 8 9.00%
"2.3 - 2.3.2
" Gingerbread 9 0.20%
"2.3.3 - 2.3.7
" 10 47.40%
3.1 Honeycomb 12 0.40%
3.2 13 1.10%
4.0.3 - 4.0.4 Ice Cream Sandwich 15 29.10%
4.1 Jelly Bean 16 9.00%
4.2 17 1.20%
這裏的問題是與該行立即合併單元格後,作爲TD計數是3而不是4 我發現,用於創建合併單元格行跨度= 2已使用在代碼中,但我想知道如何使用這些信息f或獲取數據完全一樣,下面是HTML結構
<tr>
<td>
<a href="/about/versions/android-2.3.html">2.3 - 2.3.2</a>
</td>
<td rowspan="2">Gingerbread</td>
<td>9</td>
<td>0.2%</td>
</tr>
<tr>
<td>
<a href="/about/versions/android-2.3.3.html">2.3.3 - 2.3.7 </a>
</td>
<td>10</td>
<td>47.4%</td>
</tr>