from bs4 import BeautifulSoup
def process_html_file(file_path):
# Open and read the HTML file
with open(file_path, 'r', encoding='utf-8') as file:
soup = BeautifulSoup(file, 'html.parser')
# Process the soup object as needed
# For example, finding all 'a' tags and processing them
for a_tag in soup.find_all('a'):
print(f"Current page: {a_tag['href']}")
choice = input("Delete this page? (y/n): ")
if choice.lower() == 'y':
a_tag.decompose() # Remove the tag
else:
new_name = input("Enter new name for this page or press Enter to keep it unchanged: ")
if new_name:
a_tag['href'] = new_name
# Write the modified HTML back to a new file
with open('modified_index.html', 'w', encoding='utf-8') as file:
file.write(str(soup))
# Call the function with your HTML file
process_html_file('index.html')