Я хочу удалить <br>
и
из очищенной таблицы HTML, используя Python и bs4.
Таблица HTML:
<tr>
<td style="width: 15; BORDER-BOTTOM: 1px solid">col1</td>
<td colspan="2" style="width: 120; BORDER-BOTTOM: 1px solid"> col2</td>
<td style="width: 50; BORDER-BOTTOM: 1px solid">col3</td>
<td style="width: 50; BORDER-BOTTOM: 1px solid">col5</td>
<td style="width: 50; BORDER-BOTTOM: 1px solid">col6</td>
<td style="width: 90; BORDER-BOTTOM: 1px solid" align="center">col7</td>
<td style="width: 90; BORDER-BOTTOM: 1px solid" align="center">col8</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid">col9</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid">col
<br> 1
<br>0</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid">col11</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid" >col12</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid">col13</td>
<td style="width: 10; BORDER-BOTTOM: 1px solid">col14</td>
<td style="width:10;BORDER-BOTTOM: 1px solid;" >col15</td>
</tr>
<tr bordercolor="#000000" class="rows1">
<td align="left"> 1</td>
<td colspan="2" style="BORDER-LEFT: 1px solid" align="left"> 123456789</td>
<td style="BORDER-LEFT: 1px solid" align="left"> John </td>
<td style="BORDER-LEFT: 1px solid" align="left"> Doe </td>
<td style="BORDER-LEFT: 1px solid" align="left"> </td>
<td style="BORDER-LEFT: 1px solid" align="right"> 3.000</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 0,00</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 30</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 0</td>
<td style="BORDER-LEFT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid;BORDER-RIGHT: 1px solid;" align="right"> 5000</td>
</tr>
<tr bordercolor="#000000" class="rows0">
<td align="left"> 2</td>
<td colspan="2" style="BORDER-LEFT: 1px solid" align="left"> 123456789</td>
<td style="BORDER-LEFT: 1px solid" align="left"> Jane </td>
<td style="BORDER-LEFT: 1px solid" align="left"> Doe </td>
<td style="BORDER-LEFT: 1px solid" align="left"> </td>
<td style="BORDER-LEFT: 1px solid" align="right"> 3.000</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 0,00</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 30</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 0</td>
<td style="BORDER-LEFT: 1px solid" align="right"> 3</td>
<td style="BORDER-LEFT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid" align="right"> </td>
<td style="BORDER-LEFT: 1px solid;BORDER-RIGHT: 1px solid;" align="right"> 5000</td>
</tr>
Код Python:
import requests
import bs4
url = "http://www.example.com/test.html"
r = requests.get(url)
html = r.text
soup = bs4.BeautifulSoup(html, 'html.parser')
tables = soup.findAll('table')[1]
for tr in tables.findAll('tr')[0:3]:
cols = tr.findAll('td')
for tds in cols:
print ('{:5}'.format(str(tds.text)), end="")
print()