#๐Ÿ”’ Soup not getting last element with same attribute

5 messages ยท Page 1 of 1 (latest)

rustic swallow
#
def test():
        response = get_response(user_status="owned", user=redacted, page_number=1)
        soup = BeautifulSoup(response, "html.parser", from_encoding="utf-8")
    
        god_help_me = []

        parent = soup.find("div", {"class": "item-icons"})
        children = parent.findChildren("span", recursive=False)
        for child in children:
            if "item-icon" in child.attrs["class"]:
                continue;
        
            god_help_me.append(child)

        print(child)

So there is supposed to be 90, but kept getting 89 in my algorithm. Consequently, I wanted to know which element did not contain the class "item-icon", and... sigh

<span class="item-icon">
<a class="tbx-tooltip item-root-0 item-category-2" href="/item/218652">
<img alt="Love Live! School Idol Project - Koizumi Hanayo - Nendoroid  (#496) (Good Smile Company)" src="https://static.myfigurecollection.net/upload/items/0/218652-5f685.jpg"/>
<meta content="1:218652" name="vars"/>
</a>
</span>``
floral boltBOT
#

@rustic swallow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rustic swallow
#

I don't understand why BS4 not detecting the class

floral boltBOT
#

@rustic swallow

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.