Beautifulsoup is a Python library used for web scraping. This powerful python tool can also be used to modify html webpages. This article depicts how beautifulsoup can be employed to change contents within a tag and replace the contents to be changed with the given string. For this, replace_with() function of the module is used.
- Import module
- Scrap data from webpage
- Parse the string scraped to html
- Select tag within which replacement has to be performed
- Add string in place of the existing one using replace_with() function
- Print replaced content
<a href=”http://gfg.com/”>Geeks for Geeks <p>gfg.in</p></a>
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.