[Python-es] Extraer datos entre tags

Kiko kikocorreoso en gmail.com
Vie Abr 5 18:30:44 CEST 2013


El 5 de abril de 2013 16:01, Harenson Henao <harenson en gmail.com> escribió:

> Hola, esto te puede orientar
> http://docs.python.org/2/library/xml.etree.elementtree.html
>

Y/o esto (siendo bruto y poco elegante):
http://docs.python.org/2/library/string.html#string.split


kk = """
<listitem>
    <variable name="UUID">2bd9c142-9e91-4182-b85c-5bb616823bd9</variable>
    <variable name="Name">kurokysan</variable>
    <variable name="AccStatus">1</variable>
    <variable name="WWWFilter">JARSP</variable>
    <variable name="UseTemplate">1</variable>
    <variable name="Rights">0</variable>
    <variable name="AdmFilter">JARSP</variable>
    <variable name="QuotaDayEnabled">0</variable>
    <variable name="QuotaDayType"></variable>
    <variable name="QuotaDay">5242880</variable>
    <variable name="QuotaWeekEnabled">0</variable>
    <variable name="QuotaWeekType"></variable>
    <variable name="QuotaWeek">0</variable>
    <variable name="QuotaMonthEnabled">0</variable>
    <variable name="QuotaMonthType"></variable>
    <variable name="QuotaMonth">0</variable>
    <variable name="QuotaAction"></variable>
    <variable name="QuotaSendAlert">0</variable>
    <variable name="Lang">detect</variable>
    <variable name="DontUseLangTemp">0</variable>
    <variable name="DetectedLang"></variable>
</listitem>""".split('\"')
usuario = kk[kk.index('Name')+1].split('>')[1].split('<')[0]
quota =   kk[kk.index('QuotaDay')+1].split('>')[1].split('<')[0]


y/o usando expresiones regulares, ejemplos y enlaces a documentación aquí:
http://pybonacci.wordpress.com/2013/02/21/regex-mediante-ejemplos/

Si no entiendes algo de lo anterior sigue preguntando.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20130405/7fe23713/attachment.html>


Más información sobre la lista de distribución Python-es