Copy of BeautifulSoup object does not preserve element_classes

16 views
Skip to first unread message

Jošt Prevc

unread,
Mar 4, 2024, 3:34:47 PMMar 4
to beautifulsoup
The code below shows the problem where making a copy does not preserve the element_classes value in the copied soup.

import bs4
import copy

class CustomTag(bs4.Tag):
    pass

soup = bs4.BeaoutifulSoup("", element_classes={bs4.Tag: CustomTag})

soup_copy = copy.copy(soup)

print(soup_copy.element_classes)  # This is "{}" but should be "{bs4.Tag: CustomTag}"

As I reviewed the source code, I think the problem is in the implementation of the BeautifulSoup.__copy__ method?
Reply all
Reply to author
Forward
0 new messages