parsel_get_selector_text
parsel_get_selector_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_get_selector_text, use pip:
pip install parsel_get_selector_text
Usage
Function: parsel_sel_get_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): TheparselSelector 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 isTrue.
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_get_selector_text import parsel_sel_get_text
html_content = """
<html>
<body>
<div id="content">
<p>Hello, world!</p>
<p>Welcome to the parsel_get_selector_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 = parsel_sel_get_text(parsel_sel=selector, xpath=xpath_query)
print(extracted_text)
Output
Hello, world!
Welcome to the parsel_get_selector_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.
Metadata
Release files for parsel-get-selector-text 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| parsel_get_selector_text-0.8.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| parsel_get_selector_text-0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / parsel_get_selector_text-0.8.tar.gz
| Download URL | parsel_get_selector_text-0.8.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9212a50197a841c0bff5ece1a30ff8a33f78981dae57f8352cda9a6700b43ad1
|
|
BLAKE2b-256 checksum How to use checksums |
693a027176495d31528bac69532e3ddc3f720425387e1e125eb512da8ee629b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / parsel_get_selector_text-0.8-py3-none-any.whl
| Download URL | parsel_get_selector_text-0.8-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbb21a459aa95b7f16ff59ec2d9937c6c45c5c7c84aa31d58f1e4948d15002b7
|
|
BLAKE2b-256 checksum How to use checksums |
1abc0c3dd84551275f2f90b1b8cb58a2d2813cecd160f3b8a4340846b8d3cb31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for parsel-get-selector-text 0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.