代码之家  ›  专栏  ›  技术社区  ›  bagere

在python中加入xml元素.text

  •  1
  • bagere  · 技术社区  · 11 年前

    python中是否有一些函数用于连接具有相同element.tag名称的element.text?

    例子:

     p>     
            some text
            <i>(</i>
            <i>something</i>
            <i>something</i>
            <i>)</i>
            some text
            <i>proň, zač</i>
            the end of paragraph
        </p>
    

    我想要什么:

     p>     
            some text
            <i>(something something)</i>
            some text
            <i>proň, zač</i>
            the end of paragraph
        </p>
    
    1 回复  |  直到 11 年前
        1
  •  1
  •   Marcin    11 年前

    python中是否有一些函数用于连接具有相同标签名称的element.text?

    不,你必须自己编码。原因是该库处理的是xml,而不仅仅是xhtml。一般来说 <tag>a</tag><tag>b</tag> <tag>ab</tag> 事实上,即使在html中 <p> <block> 标签会改变文本的含义。