Bo Peng
Bo Peng

Reputation: 603

How to turn raw string to `bs4.element.Tag`

How can I turn raw string: `

string = "<p color="#000000" font_size="11">Sample Text</p>"`

into a beautiful soup tag? bs4.element.Tag

Thanks.

Upvotes: 1

Views: 418

Answers (1)

snapcrack
snapcrack

Reputation: 1813

You can just use BeautifulSoup on the string:

string = '<p color="000000" font_size=11>Sample Text</p>'

soup = BeautifulSoup(string)

In: soup.find('p')
Out: <p color="000000" font_size="11">Sample Text</p>

In: type(soup.find('p'))
Out: bs4.element.Tag

Upvotes: 2

Related Questions