# parsel_text
`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:
```bash
pip install parsel_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`): 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:
```python
from parsel import Selector
from parsel_text import parsel_sel_get_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 = parsel_sel_get_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](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "parsel-text",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "dom, parsel, scraping, xpath",
"author": null,
"author_email": "\"Carlos A. Planch\u00f3n\" <carlosandresplanchonprestes@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/9a/27/917d52c6c977e27dcc2dba23245211bc32e5fd556089546862c7d65458c0/parsel_text-1.1.tar.gz",
"platform": null,
"description": "# parsel_text\n\n`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).\n\n## Installation\n\nTo install `parsel_text`, use pip:\n\n```bash\npip install parsel_text\n```\n\n## Usage\n\n### Function: `parsel_sel_get_text`\n\nThis is the main function of the library, designed to extract all text results from an XPath query on a `parsel` Selector object.\n\n#### Parameters\n\n- `parsel_sel` (`parsel.Selector`): The `parsel` Selector object from which to extract text.\n- `xpath` (`str`): The XPath query string to specify the text extraction path.\n- `fix_mojibake` (`bool`, optional): A flag to indicate whether to fix mojibake issues in the extracted text. Default is `True`.\n\n#### Returns\n\n- `str`: A string containing the concatenated text results from the specified XPath query.\n\n### Example\n\nHere's a simple example of how to use the `parsel_sel_get_text` function:\n\n```python\nfrom parsel import Selector\nfrom parsel_text import parsel_sel_get_text\n\nhtml_content = \"\"\"\n<html>\n <body>\n <div id=\"content\">\n <p>Hello, world!</p>\n <p>Welcome to the parsel_text library.</p>\n </div>\n </body>\n</html>\n\"\"\"\n\n# Create a parsel Selector object\nselector = Selector(text=html_content)\n\n# Define the XPath query\nxpath_query = \"//div[@id='content']/p//text()\"\n\n# Extract text using the parsel_sel_get_text function\nextracted_text = parsel_sel_get_text(parsel_sel=selector, xpath=xpath_query)\n\nprint(extracted_text)\n```\n\n#### Output\n\n```\nHello, world!\nWelcome to the parsel_text library.\n```\n\n## Contributing\n\nContributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Extracts all text results from an XPath query on a parsel Selector object.",
"version": "1.1",
"project_urls": {
"repository": "https://github.com/carlosplanchon/parsel_text.git"
},
"split_keywords": [
"dom",
" parsel",
" scraping",
" xpath"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fb713e4407a1000b3640554101796ab56d6c093c9f982a6bda75a2108a1771be",
"md5": "949d27069450f50955a385a15cf3e0c1",
"sha256": "4ae2ba97ddb7265a07e82b19c0f00d13a62ee98f5263afb65ac5ab59f48d5257"
},
"downloads": -1,
"filename": "parsel_text-1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "949d27069450f50955a385a15cf3e0c1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4215,
"upload_time": "2024-12-03T02:45:25",
"upload_time_iso_8601": "2024-12-03T02:45:25.229787Z",
"url": "https://files.pythonhosted.org/packages/fb/71/3e4407a1000b3640554101796ab56d6c093c9f982a6bda75a2108a1771be/parsel_text-1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9a27917d52c6c977e27dcc2dba23245211bc32e5fd556089546862c7d65458c0",
"md5": "f36485ecc20692e1b0bd2d971f5b7935",
"sha256": "a4808810a5cff9ffc95f79715f733847b54efadef420009030f6c48ffe143c5c"
},
"downloads": -1,
"filename": "parsel_text-1.1.tar.gz",
"has_sig": false,
"md5_digest": "f36485ecc20692e1b0bd2d971f5b7935",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4007,
"upload_time": "2024-12-03T02:45:26",
"upload_time_iso_8601": "2024-12-03T02:45:26.881774Z",
"url": "https://files.pythonhosted.org/packages/9a/27/917d52c6c977e27dcc2dba23245211bc32e5fd556089546862c7d65458c0/parsel_text-1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 02:45:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "carlosplanchon",
"github_project": "parsel_text",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "bs4",
"specs": []
},
{
"name": "ftfy",
"specs": []
},
{
"name": "parsel",
"specs": []
}
],
"lcname": "parsel-text"
}