Obtenez de l'Attribut href du Lien de balise td BeautifulSoup Python
Je suis nouveau en Python et quelqu'un m'a suggéré d'utiliser Belle soupe pour la mise au Rebut et je me suis heurté à un problème pour récupérer l'attribut href d'une balise td Colonne 2 sur la base de l'année dans la colonne 4.
<table class="tableFile2" summary="Results">
<tr>
<th width="7%" scope="col">Filings</th>
<th width="10%" scope="col">Format</th>
<th scope="col">Description</th>
<th width="10%" scope="col">Filing Date</th>
<th width="15%" scope="col">File/Film Number</th>
</tr>
<tr>
<td nowrap="nowrap">8-K</td>
<td nowrap="nowrap"><a href="/Archives/edgar/data/320193/000119312513199324/0001193125-13-199324-index.htm" id="documentsbutton"> Documents</a></td>
<td class="small" >Current report, items 8.01 and 9.01
<br />Acc-no: 0001193125</td>
<td>2013-05-03</td>
<td nowrap="nowrap"><a href="/cgi-bin/browse-edgar?action=getcompany&filenum=000-10030&owner=include&count=40">000-10030</a><br>13813281 </td>
</tr>
<tr class="blueRow">
<td nowrap="nowrap">424B2</td>
<td nowrap="nowrap"><a href="/Archives/edgar/data/320193/000119312513191849/0001193125-13-191849-index.htm" id="documentsbutton"> Documents</a></td>
<td class="small" >Prospectus [Rule 424(b)(2)]<br />Acc-no: 0001193125</td>
<td>2013-05-01</td>
<td nowrap="nowrap"><a href="/cgi-bin/browse-edgar?action=getcompany&filenum=333-188191&owner=include&count=40">333-188191</a><br>13802405 </td>
</tr>
<tr>
<td nowrap="nowrap">FWP</td>
<td nowrap="nowrap"><a href="/Archives/edgar/data/320193/000119312513189053/0001193125-13-189053-index.htm" id="documentsbutton"> Documents</a></td>
<td class="small" >Filing under Securities Act Rules 163/433 of free writing prospectuses<br />Acc-no: 0001193125-13-189053 (34 Act) Size: 52 KB </td>
<td>2013-05-01</td>
<td nowrap="nowrap"><a href="/cgi-bin/browse-edgar?action=getcompany&filenum=333-188191&owner=include&count=40">333-188191</a><br>13800170 </td>
</tr>
</table>
table = soup.find('table', class="tableFile2")
rows = table.findAll('tr')
for tr in rows:
cols = tr.findAll('td')
if "2013" in cols[3]
link = cols[1].find('a').get('href')
print
Si vous souhaitez que les données des colonnes
Format
et Filing Date
?
OriginalL'auteur Zaid Iqbal | 2013-05-24
Vous devez vous connecter pour publier un commentaire.
Cela fonctionne pour moi en Python 2.7:
Quelques problèmes avec votre code précédent:
soup.find()
nécessite un dictionnaire d'attributs (par exemple,{'class' : 'tableFile2'}
)cols
instance aura au moins 3 colonnes, de sorte que vous devez vérifier d'abord la longueur.OriginalL'auteur Charles Marsh