Copy of BeautifulSoup object does not preserve element_classes

閲覧: 15 回
最初の未読メッセージにスキップ

Jošt Prevc

未読、
2024/03/04 15:34:473月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?
全員に返信
投稿者に返信
転送
新着メール 0 件