Beautifulsoup,查找htm中唯一没有属性的标记

2024-06-17 16:07:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道…从标题上看,这个答案似乎和其他成千上万的答案一样。但我仍然搜索了所有相关和类似的问题。我想问的是,考虑到这个html(只是一个示例):

<html>

<body>
    <div class="div-share noprint">
        <div class="addthis_toolbox addthis_default_style">
            <a class="btn btn-xs btn-share addthis_button_facebook" href="https://somelink" target="_blank">
                <span class="playblk"><img alt="someimg" class="playblk" height="25" src="some source" title="sometitle" width="25"/></span>
            </a>
            <a class="btn btn-xs btn-share addthis_button_facebook" href="https://somelink" target="_blank">
                <span class="playblk"><img alt="someimg" class="playblk" height="25" src="some source" title="sometitle" width="25"/></span>
            </a>
        </div>
    </div>
    <div class="addthis_toolbox addthis_default_style">
        <a class="btn btn-xs btn-share addthis_button_facebook" href="https://somelink" target="_blank">
            <span class="playblk"><img alt="some img" class="playblk" height="25" src="othersource" title="some othertitle" width="25"/></span>
        </a>
    </div>
    <div class="div-share">
        <h1>"The Divine Wings Of Tragedy" lyrics</h1></div>,
    <div class="pther">
        <h2><b>Symphony X Lyrics</b></h2>
    </div>
    <div class="ringtone">
        <span id="cf_text_top"></span>
    </div>
    <div>
        <i>[Part I - At the Four Corners of the Earth]</i>
        <br/>
        <br/> On the edge of paradise
        <br/> Tears of woe fall, cold as ice
        <br/> Hear my cry
        <br/>
    </div>
</body>

</html>

我想找到唯一一个没有属性的标记。不是像我在其他问题中看到的empy属性,也不是奇怪的特定属性,或者attrs=None。。。那个标签没有别的东西。但是如果我使用findAll,我会在html中找到所有其他标记。如果我使用attrs=False、attrs=None等等,也是一样的

那么有可能吗

非常感谢


Tags: brdivshareimgfacebookhtmlbuttonsome