Two Vital Python Programming Approaches For Your Website’s SEO
Dr. Tuhin Banik
Founder of ThatWare?, Forbes Agency Council, Forbes DGEMs 200 | Pioneering Hyper-Intelligence & AI-based SEO | TEDx & Brighton Speaker | International SEO Expert | 100 Influential Tech Leaders | Global Frontrunner in SEO
What is Natural Language Processing (NLP)?
Natural language processing (NLP) is a branch of artificial intelligence focused on computer science. NLP’s primary goal is to give computers the ability to understand written text, human language, and analyze large corpuses of natural language data.
Go to textrazor.com so you can set up your account.
Click “Free API Key” and go through the process of entering your information and verifying your email so you can grab your free API key.
Run the first cell to install and import TextRazor?
Group Entities by URL and Count Entity Mentions
Visualize Entities Using Plotly
Bulk Canonical Tag Generator Using Python
A canonical tag (or rel=canonical) is a small piece of HTML code that helps search engines to determine the “main” version of the page from the rest of the pages that are identical or very similar to it.
Step 1:
Create a folder on desktop. And –
Create an xlsx file, rename it to “input”
Take the URLs from screaming frog, and paste it on url_column tab.(Only relevant URL or desired URLs)
Now, paste the same urls on the canonical column for self-referencing canonical tag, or you can set any desired canonical for desired url.
Now save it.
Step 2:
?Copy the this python code and save it on that folder –?
import openpyxl
def generate_canonical_tags(filename):
??# Load the XLSX file
??workbook = openpyxl.load_workbook(filename)
??sheet = workbook.active
??# Get the maximum number of rows in the sheet
??max_row = sheet.max_row
??# Define the column indices for relevant data
??url_column = 1
??canonical_column = 2
领英推荐
??# Iterate over the rows and generate the Canonical Tags
??canonical_tags = []
??for row in range(2, max_row + 1):?# Start from row 2, assuming headers are in row 1
????url = sheet.cell(row=row, column=url_column).value
????canonical = sheet.cell(row=row, column=canonical_column).value
????if url and canonical:
??????canonical_tag = f'<link rel=”canonical” href=”{canonical}” />’
??????canonical_tags.append((url, canonical_tag))
??return canonical_tags
# Example usage
input_filename = ‘input.xlsx’
output_filename = ‘output.xlsx’
# Generate Canonical Tags
canonical_tags = generate_canonical_tags(input_filename)
# Create a new workbook and sheet for output
output_workbook = openpyxl.Workbook()
output_sheet = output_workbook.active
# Write the headers
output_sheet.cell(row=1, column=1).value = ‘URL’
output_sheet.cell(row=1, column=2).value = ‘Canonical Tag’
# Write the generated Canonical Tags to the sheet
for row, (url, canonical_tag) in enumerate(canonical_tags, start=2):
??output_sheet.cell(row=row, column=1).value = url
??output_sheet.cell(row=row, column=2).value = canonical_tag
# Save the output workbook to a file
output_workbook.save(output_filename)
print(f”Canonical Tags generated and saved to ‘{output_filename}’ successfully!”)
Rename it “canonical”
Like this –
Now open anaconda prompt –
And select your folder using cd command –
And type – python canonical.py
The file is generated for bulk canonical tags –
Now we can implement those tags on head section of desired pages.
Source: https://thatware.co/python-programming-for-seo/