• <i id='RHMRW'><tr id='RHMRW'><dt id='RHMRW'><q id='RHMRW'><span id='RHMRW'><b id='RHMRW'><form id='RHMRW'><ins id='RHMRW'></ins><ul id='RHMRW'></ul><sub id='RHMRW'></sub></form><legend id='RHMRW'></legend><bdo id='RHMRW'><pre id='RHMRW'><center id='RHMRW'></center></pre></bdo></b><th id='RHMRW'></th></span></q></dt></tr></i><div id='RHMRW'><tfoot id='RHMRW'></tfoot><dl id='RHMRW'><fieldset id='RHMRW'></fieldset></dl></div>

    <tfoot id='RHMRW'></tfoot>

      <small id='RHMRW'></small><noframes id='RHMRW'>

      <legend id='RHMRW'><style id='RHMRW'><dir id='RHMRW'><q id='RHMRW'></q></dir></style></legend>
      • <bdo id='RHMRW'></bdo><ul id='RHMRW'></ul>

        如何使用 LXML 递归查找 XML 标记?

        How to find recursively for a tag of XML using LXML?(如何使用 LXML 递归查找 XML 标记?)

      1. <legend id='Y8Ikf'><style id='Y8Ikf'><dir id='Y8Ikf'><q id='Y8Ikf'></q></dir></style></legend>
          <bdo id='Y8Ikf'></bdo><ul id='Y8Ikf'></ul>

                <tbody id='Y8Ikf'></tbody>

                  <small id='Y8Ikf'></small><noframes id='Y8Ikf'>

                • <tfoot id='Y8Ikf'></tfoot>
                • <i id='Y8Ikf'><tr id='Y8Ikf'><dt id='Y8Ikf'><q id='Y8Ikf'><span id='Y8Ikf'><b id='Y8Ikf'><form id='Y8Ikf'><ins id='Y8Ikf'></ins><ul id='Y8Ikf'></ul><sub id='Y8Ikf'></sub></form><legend id='Y8Ikf'></legend><bdo id='Y8Ikf'><pre id='Y8Ikf'><center id='Y8Ikf'></center></pre></bdo></b><th id='Y8Ikf'></th></span></q></dt></tr></i><div id='Y8Ikf'><tfoot id='Y8Ikf'></tfoot><dl id='Y8Ikf'><fieldset id='Y8Ikf'></fieldset></dl></div>
                  本文介绍了如何使用 LXML 递归查找 XML 标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  <?xml version="1.0" ?>
                  <data>
                      <test >
                          <f1 />
                      </test >
                      <test2 >
                          <test3>
                           <f1 />
                          </test3>
                      </test2>
                      <f1 />
                  </data>
                  

                  使用 lxml 是否可以递归地找到标签"f1 "?我尝试了 findall 方法,但它只适用于直系子女.

                  Using lxml is it possible to find recursively for tag " f1 "? I tried findall method but it works only for immediate children.

                  我想我应该为此选择 BeautifulSoup !!!

                  I think I should go for BeautifulSoup for this !!!

                  推荐答案

                  可以使用XPath递归搜索:

                  You can use XPath to search recursively:

                  >>> from lxml import etree
                  >>> q = etree.fromstring('<xml><hello>a</hello><x><hello>b</hello></x></xml>')
                  >>> q.findall('hello')     # Tag name, first level only.
                  [<Element hello at 414a7c8>]
                  >>> q.findall('.//hello')  # XPath, recursive.
                  [<Element hello at 414a7c8>, <Element hello at 414a818>]
                  

                  这篇关于如何使用 LXML 递归查找 XML 标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                  <i id='yhLee'><tr id='yhLee'><dt id='yhLee'><q id='yhLee'><span id='yhLee'><b id='yhLee'><form id='yhLee'><ins id='yhLee'></ins><ul id='yhLee'></ul><sub id='yhLee'></sub></form><legend id='yhLee'></legend><bdo id='yhLee'><pre id='yhLee'><center id='yhLee'></center></pre></bdo></b><th id='yhLee'></th></span></q></dt></tr></i><div id='yhLee'><tfoot id='yhLee'></tfoot><dl id='yhLee'><fieldset id='yhLee'></fieldset></dl></div>

                  • <bdo id='yhLee'></bdo><ul id='yhLee'></ul>
                      • <tfoot id='yhLee'></tfoot>
                              <tbody id='yhLee'></tbody>

                            <small id='yhLee'></small><noframes id='yhLee'>

                            <legend id='yhLee'><style id='yhLee'><dir id='yhLee'><q id='yhLee'></q></dir></style></legend>