0
我的HTML:如何用BeautifulSoup和Regex解析這個HTML表格?
<table cellspacing="0" cellpadding="2" rules="all" border="1" id="branchTable" width="100%">
<tr class="TitleTable">
<th scope="col" width="250"><b>Branch Name</b></th><th scope="col" width="35%"><b>Branch Date</b></th><th scope="col" width="35%"><b>Branch Origin</b></th>
</tr><tr class="RowSet">
<td><a class="blue" href="javascript: OpenWindow('/home/data/files/fetchRecord.php?fileID=342')">SFO Branch</a></td><td class="red">03/16/2012</td><td class="red"> </td>
</tr><tr class="RowSet">
<td><a class="blue" href="javascript: OpenWindow('/home/data/files/fetchRecord.php?fileID=884')">LAX Branch</a></td><td class="red">03/16/2012</td><td class="red">06/16/1985</td>
</tr><tr class="RowSet">
<td><a class="blue" href="javascript: OpenWindow('/home/data/files/fetchRecord.php?fileID=83')">DC Branch</a></td><td class="red">03/16/2012</td><td class="red"> </td>
</tr>
</table>
到目前爲止我的代碼:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(pageSource)
table = soup.find("table", id = "branchTable")
rows = table.findAll("tr", {"class":"RowSet"})
data = [[td.findChildren(text=True) for td in tr.findAll("td")] for tr in rows]
print data
輸出:
SFO Branch 03/16/2012
LAX Branch 03/16/2012 06/16/1985
DC Branch 03/16/2012
期望:
我想抓住封閉在標籤中的數據以及ID(fetchRecord.php?fileID = )。不知道如何獲取該值。 BeautifulSoup或正則表達式,請幫助。謝謝!
什麼是U究竟意欲何爲? –
解析html並獲取輸出中顯示的數據。我也想抓住fileID,不知道該怎麼做。 – ThinkCode