Two Vital Python Programming Approaches For Your Website’s SEO

Two Vital Python Programming Approaches For Your Website’s 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.

No alt text provided for this image

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.

No alt text provided for this image
No alt text provided for this image

  1. Install TextRazor and other Python Libraries?


No alt text provided for this image

Run the first cell to install and import TextRazor?

No alt text provided for this image

Group Entities by URL and Count Entity Mentions

No alt text provided for this image

Visualize Entities Using Plotly

No alt text provided for this image

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”

No alt text provided for this image

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.

No alt text provided for this image

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 –

No alt text provided for this image

Now open anaconda prompt –

And select your folder using cd command –

No alt text provided for this image

And type – python canonical.py

No alt text provided for this image

The file is generated for bulk canonical tags –

No alt text provided for this image

Now we can implement those tags on head section of desired pages.

Source: https://thatware.co/python-programming-for-seo/

要查看或添加评论,请登录

社区洞察

其他会员也浏览了