Hi, all nice people here, I’m trying to build multiple different seo optimized versions starting from a html template (let’s call it pagetemplate.html) filled with placeholders ({placeholder}) and a data filled csv file (data.csv) which contains the list of keywords to be targeted in the first csv column and the rest of columns contain the corresponding data that will replace the placeholders accordingly in the html template pagetemplate.html
the corresponding data to name most if them not all are :
- Title tag , placeholder = {title}
- description tag , — = {description}
- h1,h2,h3 , ---- = {h1} , {h2} , {h3}
- author tag
-footer tag - image alt tag
- schema tags
- open graph tags
-Twitter Card Meta Tags - And off course whole body text content of the page.
Which because of its big size and legnth it’s not practical to be put directly inside the csv file but it instead must be called from its txt file from another folder by putting only its file path ( these text content files pathes are put in one column in data.csv and called by the script to be placed in the pagetemplate.html accordingly to each keyword like all other data)
the written python script must carefully and perfectly craft the created html pages versions of pagetemplate.html for each keyword and save them under dashed file names using the corresponding keyword ( the spaces in keywords must be removed and replaced by dashes before the .html extension)
finally the script must do another important task : it must link all the created html pages sequentionally one to another ( firstpage.html links to secondpage.html
with anchor text in link
secondpage.html links to thirdpage.html
with anchor text in link
thirdpage.html links to fourthpage.html
with anchor text in link and so on so forth
until the last page that liops the the first page
lastpage.html links to the first page with anchor text in link
to be mentionned that anchor text are the correspinding keywords to linked-to pages.
The links must be placed in the bottom line of each page. With a font size = 15.
I’ve tried to make this script using Ai codes generators but it didn’t work although they seemed to be promising
here a draft of what i got of one of them but it didn’t work idon’t know why since i’m total newbie and specially i don’t have time to get over the learning curve , i need some kind souls to help get rid of this struggle with all my thanks and gratitude
Import necessary libraries
import pandas as pd
Read data from the CSV file
data = pd.read_csv(‘data.csv’)
Read the HTML template
with open(‘pagetemplate.html’, ‘r’) as file:
template = file.read()
Loop through each row in the CSV file
for index, row in data.iterrows():
keyword = row[‘Keyword’].replace(’ ', ‘-’)
title = row[‘Title’]
description = row[‘Description’]
h1 = row[‘H1’]
h2 = row[‘H2’]
h3 = row[‘H3’]
# Add more variables for other data fields
# Replace the placeholders in the HTML template with actual data
page_content = template.replace('{title}', title)\
.replace('{description}', description)\
.replace('{h1}', h1)\
.replace('{h2}', h2)\
.replace('{h3}', h3)
# Add more replacements for other data fields
# Write the generated HTML page to a new file
with open(f'{keyword}.html', 'w') as new_file:
new_file.write(page_content)
Create sequential links at the bottom of each page
pages = data[‘Keyword’].tolist()
for i in range(len(pages)):
current_page = pages[i]
next_page = pages[(i + 1) % len(pages)]
link = f’{next_page}’
link_html = f’
{link}
’# Append the link to the current page
with open(f'{current_page}.html', 'a') as file:
file.write(link_html)
here another script from another ai code generator to help better understand what i’m trying to get
import csv
def build_seo_optimized_pages(html_template_file, data_csv_file, output_folder):
“”"
Function to build multiple SEO optimized pages from an HTML template filled with placeholders and a CSV file containing data.
Parameters:
- html_template_file: str
The file path to the HTML template file with placeholders.
- data_csv_file: str
The file path to the CSV file containing keywords and corresponding data.
- output_folder: str
The folder path where the generated SEO optimized pages will be saved.
Returns:
- None
Process:
1. Read the HTML template file.
2. Read the data CSV file.
3. For each row in the CSV file:
- Replace the placeholders in the HTML template with the corresponding data.
- Save the SEO optimized page in the output folder with a filename based on the keyword.
Note:
- The placeholders in the HTML template should be in the format {placeholder}.
- The first column in the CSV file should contain the keywords.
- The rest of the columns contain the data to replace the placeholders in the HTML template.
"""
# Read the HTML template file
with open(html_template_file, 'r') as template_file:
html_template = template_file.read()
# Read the data CSV file
with open(data_csv_file, 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip header row
for row in csv_reader:
keyword = row[0]
data = row[1:]
# Replace placeholders in the HTML template with corresponding data
seo_page_content = html_template
for i, placeholder in enumerate(data):
placeholder_to_replace = '{' + f'placeholder{i+1}' + '}'
seo_page_content = seo_page_content.replace(placeholder_to_replace, placeholder)
# Save the SEO optimized page in the output folder
output_file_path = f'{output_folder}/{keyword}.html'
with open(output_file_path, 'w') as output_file:
output_file.write(seo_page_content)
Example usage of the build_seo_optimized_pages function
build_seo_optimized_pages(‘pagetemplate.html’, ‘data.csv’, ‘output_pages’)