Appending HTML snippet to element

16 views
Skip to first unread message

Sam Sloniker

unread,
Jul 31, 2022, 12:26:34 PM7/31/22
to beauti...@googlegroups.com
I have a few hundred HTML files. I need to append the same HTML snippet to a certain element in each of them. (It's the first element with a certain class name.) I know how to select the element to append to, but how do you append HTML to an element? I see how to append text, or how to create an element in Python and append it, but not how to append HTML code.

Jairaj Sahgal

unread,
Jul 31, 2022, 6:54:44 PM7/31/22
to beauti...@googlegroups.com

I would suggest use bs4 to get elements
And convert them into string and create a new file that has parsed the entire page except that class element. When that element comes, add it with your code.

On Sun, 31 Jul 2022, 21:56 Sam Sloniker, <s...@kj7rrv.com> wrote:
I have a few hundred HTML files. I need to append the same HTML snippet to a certain element in each of them. (It's the first element with a certain class name.) I know how to select the element to append to, but how do you append HTML to an element? I see how to append text, or how to create an element in Python and append it, but not how to append HTML code.

--
You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beautifulsou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beautifulsoup/53b-62e56a00-d-4585b580%40252821711.
Reply all
Reply to author
Forward
0 new messages