Skip to content
Advertisement

how to modify a saved html page?

I am trying to modify a saved html webpage. More specifically, I would like to highlight specific sentences in the page and save as a new html page.

I thought the code below would work but it does not

JavaScript

Any ideas? Thanks!

Advertisement

Answer

Here is how you can open html file, edit using bs4 and write to the new file. I assume you are trying to add style attribute to the span tag:

JavaScript

Explanation: Grab all tags contains specified text with the help find_all method and lambda function. Get whole text and replace specified text with new tag that highlights that text. Finally, write modified soup to the new file

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement