2013-01-10 21 views

risposta

36

è possibile fornire una callable come un filtro:

dates = soup.findAll("div", {"id" : lambda L: L and L.startswith('date')}) 

O come @DSM sottolinea

dates = soup.findAll("div", {"id" : re.compile('date.*')}) 

come BeautifulSoup riconosce un oggetto RegExp e chiama il suo metodo .match().

+1

Questo mi dà un errore "oggetto 'NoneType' non ha alcun attributo startswith" – user984003

+0

@ user984003 Okies - non sono sicuro che la causa Cos'hai - aggiornato dopo –

+1

Si potrebbe anche passare un'espressione regolare, come 're.compile ('data * ') '. – DSM

Problemi correlati