Skip to main content

PySeoHtml Documentation

Description

PySeoHtml is a Python library designed to intelligently link specific keywords within HTML text content. It enhances SEO (Search Engine Optimization) strategies by optimizing content with linked keywords, maintaining readability, and preventing over-optimization.

Table of Contents

  1. Installation

  2. How It Works
  3. Usage

Installation

To install PySeoHtml, you can use pip:

pip install py-seo-html

Text Processing

The library processes the HTML text and replaces keywords with links. This process includes tokenization, keyword matching, link insertion, HTML escaping, punctuation handling, and link limitation.

Randomization (Optional)

You can choose to place links randomly (if random_links is set to True), which can help avoid over-optimization penalties from search engines.

Initialization

To get started, create an instance of the PySeoHtml class by providing the following parameters:

  • html_text: The HTML text content you want to process. (Required)

  • keywords: A list of keyword-link pairs where each item is a list with the keyword and its associated link. (Required)

  • density: The maximum allowed length (in characters) for linked text snippets. (Default: 500)

  • random_links: If set to True, the library will randomly choose keywords to link each time. If False, it will consistently link the same keywords. (Default: False)

  • stemming: If set to True, keywords are stemmed before processing. (Default: True)

  • language: The language to use for stemming. Supported languages include “arabic,” “danish,” “dutch,” “english,” “finnish,” “french,” “german,” “hungarian,” “italian,” “norwegian,” “porter,” “portuguese,” “romanian,” “russian,” “spanish,” and “swedish.” (Default: “english”)

  • valid_tags: A list of HTML tags that are considered valid for keyword linking. (Default: [“p”, “h1”, “h2”, “h3”, “h4”, “h5”, “h6”])

Benefits for SEO

PySeoHtml offers several benefits for SEO:

  • Keyword Linking: It automatically identifies and links keywords to relevant URLs within your HTML content, improving search engine understanding and rankings.

  • Content Optimization: By strategically linking keywords, you can enhance the SEO value of your content and increase its visibility in search results.

  • Prevents Over-Optimization: The library limits the number of linked keywords to maintain a natural keyword density, helping you avoid SEO penalties.

  • Maintains Readability: Linked keywords are embedded within readable text snippets, improving the user experience and preventing content from appearing spammy.

Usage

Here’s an example of how to use the PySeoHtml library:

Example

from PySeoHtml import PySeoHtml

html_text = """
<h1>Enhance Your SEO with PySeoHtml</h1>
<p>PySeoHtml is a powerful Python library that can help boost your website's SEO performance. By intelligently linking specific keywords within your content, you can improve search engine rankings and increase organic traffic.</p>
<p>Here are some examples of keywords you can link:</p>
<ul>
    <li>Search Engine Optimization</li>
    <li>Keyword Research</li>
    <li>On-Page SEO</li>
    <li>Link Building</li>
</ul>
"""

keywords = [
    [["Search Engine Optimization"], "https://example.com/seo"],
    [["Keyword Research"], "https://example.com/keyword-research"],
    [["On-Page SEO"], "https://example.com/on-page-seo"],
    [["Link Building"], "https://example.com/link-building"],
    # Add more keyword-link pairs as needed
]

# Initialize PySeoHtml
seo_html = PySeoHtml(
    html_text=html_text,
    keywords=keywords,
    density=100,
    random_links=False,
    stemming=True,
    language="english",
    valid_tags=["li", "p", "h1", "h2", "h3", "h4", "h5", "h6"],
)

# Generate the processed HTML content
processed_html = seo_html.make()

print(processed_html)

Result

The processed_html variable will contain the HTML content with keywords replaced by links. This processed content can be used to enhance SEO strategies.

Thank you!

Please feel free to reach out if you have any further questions or need additional assistance!

Metadata

Release files for py-seo-html 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-seo-html 1.2.1
File Size Uploaded
py-seo-html-1.2.1.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-seo-html 1.2.1
File Interpreter ABI Platform
py_seo_html-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / py-seo-html-1.2.1.tar.gz

Download URL py-seo-html-1.2.1.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6813ebe3be8ec213dd3662551abd1bbc73c18b48722a87cd313a860e00b3ee7d
BLAKE2b-256 checksum
How to use checksums
d246dcec5f9cb462146292cc2151c6b93b408f31fa65bcd330c632bfb8613582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / py_seo_html-1.2.1-py3-none-any.whl

Download URL py_seo_html-1.2.1-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33cb67f9ccbefe4b4b781b609960c5b0ac96ba072f8cf410371773dbdd9aa614
BLAKE2b-256 checksum
How to use checksums
131f6c8c835cce54752faae2312a19b43a0a6d3a75c8e3e2ea4472fa3ef71463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page