Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/09/2011, 09:28
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Etiquetas con expresiones regulares

No uses expresiones regulares para parsear HTML. Mejor usa un parser HTML como lxml.
Código Python:
Ver original
  1. from lxml import etree
  2.  
  3. s = u"""<a href="index.php?id=1111">23/08/1980&nbsp;</a>
  4. <a href="index.php?id=1111">CARLOS RIQUELME &nbsp;</a>
  5.  
  6. <a href="index.php?id=1112">20-04-1983</a>
  7. <a href="index.php?id=1112">Luis Sobarso</a>
  8.  
  9. <a href="index.php?id=1113">11/03</a>
  10. <a href="index.php?id=1113">
  11.                
  12.                    Ana Lopez
  13.                
  14.            
  15. </a>"""
  16.  
  17. root = etree.HTML(s)
  18. for i in root.xpath("//a"):
  19.     print i.get('href'), i.text