PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/modulos/html-re.py

https://bitbucket.org/alfonsodg/curso_python_basico
Python | 53 lines | 47 code | 4 blank | 2 comment | 0 complexity | 1091b30e0f690c4b773a8c76f45c8336 MD5 | raw file
  1. # -*- coding:utf-8 -*-
  2. import re
  3. # common variables
  4. rawstr = r"""<.*?>"""
  5. embedded_rawstr = r"""(?is)<.*?>"""
  6. matchstr = """ <table cellspacing="0" cellpadding="0" width="560" border="0" ID="Table12">
  7. <tr>
  8. <td bgcolor='#DCE2EE'><div align="left"><a href="#" class="linkhover1"><b>DE LA GUARDA CHUMPITAZ HAYDEE</b></a></div></td>
  9. </tr>
  10. <tr>
  11. <td><div align="left">
  12. <table cellspacing="0" cellpadding="0" width="100%" border="0" ID="Table13">
  13. <tr>
  14. <td class="cel05">Sn Sn Bl. 49 Int. B1 Altura Del Estadio San Marcos Urb. Unidad Vecinal No.3<br>El Cercado, LIMA<br />
  15. (+51) (1) <b>538-0229</b>
  16. </td>
  17. <td width="175" align="right" valign="top"></td>
  18. </tr>
  19. </table>
  20. </div></td>
  21. </tr>
  22. <tr height="15"><td></td></tr>
  23. </table>
  24. <table cellspacing="0" cellpadding="0" width="560" border="0" ID="Table12">
  25. <tr>
  26. <td bgcolor='#DCE2EE'><div align="left"><a href="#" class="linkhover1"><b>DE LA GUARDA GONZALES DANIEL MARTIN</b></a></div></td>
  27. </tr>
  28. <tr>
  29. <td><div align="left">
  30. <table cellspacing="0" cellpadding="0" width="100%" border="0" ID="Table13">
  31. <tr>
  32. <td class="cel05">JR Saenz Peña 1412 Int. 102<br>La Victoria, LIMA<br />"""
  33. # method 1: using a compile object
  34. compile_obj = re.compile(rawstr, re.IGNORECASE| re.DOTALL)
  35. match_obj = compile_obj.search(matchstr)
  36. print match_obj.group(0)
  37. # method 2: using search function (w/ external flags)
  38. match_obj = re.search(rawstr, matchstr, re.IGNORECASE| re.DOTALL)
  39. print match_obj.group(0)
  40. # method 3: using search function (w/ embedded flags)
  41. match_obj = re.search(embedded_rawstr, matchstr)
  42. print match_obj.group(0)
  43. # Replace string
  44. #newstr = compile_obj.subn(' ', 0)