这是HTML
内容:
<table cellspacing="1" cellpadding="0" class="data">
<tr class="colhead">
<th colspan="3">Expression</th>
</tr>
<tr class="colhead">
<th>Task</th>
<th>Action</th>
<th>List</th>
</tr>
<tr class="rowLight">
<td width="40%">
Task1
</td>
<td width="20%">
Assigned to
</td>
<td width="40%">
Harry
</td>
</tr>
<tr class="rowDark">
<td width="40%">
Task2
</td>
<td width="20%">
Rejected by
</td>
<td width="40%">
Lopa
</td>
</tr>
<tr class="rowLight">
<td width="40%">
Task5
</td>
<td width="20%">
Accepted By
</td>
<td width="40%">
Mathew
</td>
</tr>
现在我必须得到如下值:(下表只是一个 Excel 表,一旦达到这些值,我将建立它。)
Task Action List
Task1 Assigned to Harry
Task2 Rejected by Lopa
Task5 Accepted By Mathew
我所知道的外行解决方案如下:
from bs4 import BeautifulSoup
soup = BeautifulSoup(source_URL)
alltables = soup.findAll( "table", {"border":"2", "width":"100%"} )
t = [x for x in soup.findAll('td')]
[x.renderContents().strip('\n') for x in t]
但是在我上面的HTML
内容中没有这样的结构,那么如何处理呢?请在这里指导我!