parsel-text


Nameparsel-text JSON
Version 1.0 PyPI version JSON
download
home_pageNone
SummaryExtracts all text results from an XPath query on a parsel Selector object.
upload_time2024-10-24 22:31:55
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License
keywords dom parsel scraping xpath
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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/0c/ae/54757d132c1509b24912f7eb3224618dc7293d6f42912bf385d5fab62f0a/parsel_text-1.0.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.0",
    "project_urls": {
        "repository": "https://github.com/carlosplanchon/parsel_text.git"
    },
    "split_keywords": [
        "dom",
        " parsel",
        " scraping",
        " xpath"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5cba63f70282d2d3b8682a0a6c30a593f7cc39f662ee5fd2a09716559950ee7",
                "md5": "1192d629d806eb8876751c1597e904c2",
                "sha256": "ae5f256f3e854a37c83892cd4a3de941ceda5740f3a79559fd260eef610a4d0e"
            },
            "downloads": -1,
            "filename": "parsel_text-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1192d629d806eb8876751c1597e904c2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4137,
            "upload_time": "2024-10-24T22:31:53",
            "upload_time_iso_8601": "2024-10-24T22:31:53.560547Z",
            "url": "https://files.pythonhosted.org/packages/a5/cb/a63f70282d2d3b8682a0a6c30a593f7cc39f662ee5fd2a09716559950ee7/parsel_text-1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cae54757d132c1509b24912f7eb3224618dc7293d6f42912bf385d5fab62f0a",
                "md5": "c8c86bca57c143d1c26b5517174dbcc6",
                "sha256": "fd33513729fc9c40fffaf4638bbb5c38ce151c40086d7319b66393743d90adf6"
            },
            "downloads": -1,
            "filename": "parsel_text-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c8c86bca57c143d1c26b5517174dbcc6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3900,
            "upload_time": "2024-10-24T22:31:55",
            "upload_time_iso_8601": "2024-10-24T22:31:55.004274Z",
            "url": "https://files.pythonhosted.org/packages/0c/ae/54757d132c1509b24912f7eb3224618dc7293d6f42912bf385d5fab62f0a/parsel_text-1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-24 22:31:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "carlosplanchon",
    "github_project": "parsel_text",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "parsel-text"
}
        
Elapsed time: 0.36942s