私の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 = 342)を取得したいと思います。その値を取得する方法がわかりません。BeautifulSoupまたはRegex、助けてください。ありがとう!