Skip to main content

Extracts all text results from an XPath query on a parsel Selector object.

Project description

parsel_text

parsel_text

CI PyPI version Python versions License: MIT DeepWiki

parsel_text is a Python library designed to simplify the extraction of text data from HTML or XML documents using XPath queries on parsel Selector objects. It provides a straightforward interface to obtain and optionally fix mojibake (garbled text due to encoding issues).

Installation

To install parsel_text, use pip:

pip install parsel_text

DeepWiki Docs: https://deepwiki.com/carlosplanchon/parsel_text

Usage

Function: get_xpath_text

This is the main function of the library, designed to extract all text results from an XPath query on a parsel Selector object.

Parameters

  • parsel_sel (parsel.Selector): The parsel Selector object from which to extract text.
  • xpath (str): The XPath query string to specify the text extraction path.
  • fix_mojibake (bool, optional): A flag to indicate whether to fix mojibake issues in the extracted text. Default is True.

Returns

  • str: A string containing the concatenated text results from the specified XPath query.

Example

Here's a simple example of how to use the parsel_sel_get_text function:

from parsel import Selector
from parsel_text import get_xpath_text

html_content = """
<html>
  <body>
    <div id="content">
      <p>Hello, world!</p>
      <p>Welcome to the parsel_text library.</p>
    </div>
  </body>
</html>
"""

# Create a parsel Selector object
selector = Selector(text=html_content)

# Define the XPath query
xpath_query = "//div[@id='content']/p//text()"

# Extract text using the parsel_sel_get_text function
extracted_text = get_xpath_text(parsel_sel=selector, xpath=xpath_query)

print(extracted_text)

Output

Hello, world!
Welcome to the parsel_text library.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

parsel_text-2.0.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

parsel_text-2.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file parsel_text-2.0.1.tar.gz.

File metadata

  • Download URL: parsel_text-2.0.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for parsel_text-2.0.1.tar.gz
Algorithm Hash digest
SHA256 e6b97d684f27ce39ea27ae532cc4d13981d6535334d450102f9dea819dcd3d44
MD5 40c1ab79e39b5903378c244615f36154
BLAKE2b-256 4210a26688f0f22e9b80105f8b90df943c01f9d36b2f1c48ff5c020e24e921f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for parsel_text-2.0.1.tar.gz:

Publisher: release.yml on carlosplanchon/parsel_text

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file parsel_text-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: parsel_text-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for parsel_text-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b512b35fcd37f8f06ec03f8a6b5954c2116068a57c7629650739da9b62c2090
MD5 f671f2c5f079c98c964edfddd26c75bb
BLAKE2b-256 0c4f465779b41e8b697e3f2c0b480f3a98ffc7c7cfbac0cf6b929e4f3186c0bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for parsel_text-2.0.1-py3-none-any.whl:

Publisher: release.yml on carlosplanchon/parsel_text

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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