Skip to main content

Python library for SEO-friendly HTML text processing and keyword linking

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-seo-html-1.1.7.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_seo_html-1.1.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file py-seo-html-1.1.7.tar.gz.

File metadata

  • Download URL: py-seo-html-1.1.7.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py-seo-html-1.1.7.tar.gz
Algorithm Hash digest
SHA256 2f3260d2ff4d10f74a5e04bc6ebbe8dd05fca2fad108d5e39edee84f04835cf3
MD5 a22e76122492fe45f977dc68f0093a27
BLAKE2b-256 75e09735992ff523a29d12239a596125a5395fd13d8c44a74a3ea56a1eb450f3

See more details on using hashes here.

File details

Details for the file py_seo_html-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: py_seo_html-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py_seo_html-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 81e4bc5e8714fb9b19881de824eefe5cdad3b29fa375dea1cfcdfc89c53c8c5f
MD5 8119386e5681c3ffd06aed227708bca1
BLAKE2b-256 b53c66114ab9ee4ebbe9de1515c5ce27191ace7fab1e0b5cbfe187f654628283

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page