简体   繁体   中英

Beautifulsoup, find the only tag in the htm that has no attribute

I know...from the title this answer seems the same oh thousand of others. BUT I have still searched all related and similar questions. What I'm asking is, given this html (just an exemple):

<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>

I want to find the only tag that has no attributes. Not an empy attr, like I saw in other questions, or a strange specific attribute, or attrs = None ... that tag has nothing else. But if I use findAll, I find all the other tag in the html. the same if I use attrs = False, attrs = None and so on..,

so there is a possibility?

thanks a lot!

您可以将 lambda 函数传递给find_all方法,该方法检查标记名称并且元素中没有find_all

soup.find_all()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM