bred

Generation

generate functionTue, 17 Jan 2023

The function takes in a link to a website, it will go to that website and replace HTML body of it with another prepared one.

from bs4 import BeautifulSoup from urllib.request import urlopen def replace(link): html = urlopen(link) soup = BeautifulSoup(html, 'html.parser') body = soup.find("body") body.clear() body.append("<h1>Hello World</h1>") print(soup.prettify()) replace("https://www.google.com/") # it will grab the HTML and replace the body with the prepared one.

Questions about programming?Chat with your personal AI assistant