久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

BeautifulSoup 計數標簽而不深入解析它們

BeautifulSoup counting tags without parsing deep inside them(BeautifulSoup 計數標簽而不深入解析它們)
本文介紹了BeautifulSoup 計數標簽而不深入解析它們的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在寫這個問題的答案時考慮了以下.

I thought about the following while writing an answer to this question.

假設我有一個像這樣深度嵌套的 xml 文件(但嵌套更多且更長):

Suppose I have a deeply nested xml file like this (but much more nested and much longer):

<section name="1">
    <subsection name"foo">
        <subsubsection name="bar">
            <deeper name="hey">
                <much_deeper name"yo">
                    <li>Some content</li>
                </much_deeper>
            </deeper>
        </subsubsection>
    </subsection>
</section>
<section name="2">
    ... and so forth
</section>

len(soup.find_all("section")) 的問題在于,在執行 find_all("section") 時,BS 一直在深入搜索一個標簽我知道不會包含任何其他 section 標記.

The problem with len(soup.find_all("section")) is that while doing find_all("section"), BS keeps searching deep into a tag that I know won't contain any other section tag.

那么,兩個問題:

  1. 有沒有辦法讓 BS 遞歸搜索到已經找到的標簽?
  2. 如果對 1 的回答是肯定的,是效率更高還是內部流程相同?
  1. Is there a way to make BS not search recursively into an already found tag?
  2. If the answer to 1 is yes, will it be more efficient or is it the same internal process?

推薦答案

BeautifulSoup 不能只提供它找到的標簽的計數/數量.

BeautifulSoup cannot give you just a count/number of tags it found.

不過,您可以改進的是:不要讓 BeautifulSoup 通過傳遞 recursive=False 來搜索其他部分中的部分:

What you, though, can improve is: don't let BeautifulSoup go searching sections inside other sections by passing recursive=False:

len(soup.find_all("section", recursive=False))

除了改進之外,lxml 會更快地完成這項工作:

Aside from that improvement, lxml would do the job faster:

tree.xpath('count(//section)')

這篇關于BeautifulSoup 計數標簽而不深入解析它們的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 日日躁狠狠躁aaaaxxxx | 中文字幕啪啪 | 精久久久久 | 日韩一二区在线 | 1204国产成人精品视频 | 精品久久久久久久人人人人传媒 | 网址黄| 久久综合婷婷 | 97天天干 | 在线视频亚洲 | 日韩国产欧美一区 | 久久99精品久久久久久青青日本 | 中文字幕精品一区久久久久 | 国产精品国产 | 综合久久综合久久 | av免费看在线 | 久久一二 | 精品久久久久久亚洲精品 | 久久久久一区二区三区四区 | 伊人国产精品 | 91社区在线观看高清 | 久久久久久久香蕉 | 99精品在线免费观看 | 欧美1级 | 亚洲精品视频一区 | av一区二区三区 | 亚洲美女在线视频 | 蜜月va乱码一区二区三区 | 精品久久久久久久久久久久久久 | 欧美一级二级在线观看 | 天天艹天天干天天 | 成人在线视频免费观看 | 日本电影韩国电影免费观看 | 中文字幕 国产 | 成人免费观看男女羞羞视频 | 日日干夜夜操 | 日日摸日日碰夜夜爽2015电影 | 国产精久久久久久久 | 99久久国产综合精品麻豆 | 欧美国产一区二区 | www.精品国产 |