Parsing non-standard XML (CDATA tag)

前端 未结 2 863
无人共我
无人共我 2020-12-19 10:20

When I want to parsing XML document in Python using BeautifulSoup library, I faced some problems. The XML document that I want to parse:




        
2条回答
  •  死守一世寂寞
    2020-12-19 11:08

    You don't need BeautifulStoneSoup or lxml. Python's included batteries do the job just fine, and there doesn't seem to be anything non-compliant about your XML.

    >>> content='''\
    ... 
    ... <![CDATA[Title Sample]]>
    ... 
    ... 2011-10-10 09:00:00
    ... 2011-10-17 09:00:00
    ... 35000
    ... 20000
    ... '''
    >>> import xml.etree.cElementTree as et
    >>> foo = et.XML(content)
    >>> for e in foo:
    ...     print e.tag, e.text, repr(e.tail)
    ...
    title Title Sample '\n'
    link None 'http://banhada.kr/?cateCode=09&viewCode=S0941580\n'
    time_start 2011-10-10 09:00:00 '\n'
    time_end 2011-10-17 09:00:00 '\n'
    price_original 35000 '\n'
    price_now 20000 '\n'
    >>>
    

提交回复
热议问题