parsel-get-selector-text


Nameparsel-get-selector-text JSON
Version 0.8 PyPI version JSON
download
home_pageNone
SummaryExtracts all text results from an XPath query on a parsel Selector object.
upload_time2024-05-22 21:22:31
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License
keywords dom parsel scraping xpath
VCS
bugtrack_url
requirements bs4 ftfy parsel
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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`): 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_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](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "parsel-get-selector-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/69/3a/027176495d31528bac69532e3ddc3f720425387e1e125eb512da8ee629b5/parsel_get_selector_text-0.8.tar.gz",
    "platform": null,
    "description": "# parsel_get_selector_text\n\n`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).\n\n## Installation\n\nTo install `parsel_get_selector_text`, use pip:\n\n```bash\npip install parsel_get_selector_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_get_selector_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_get_selector_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_get_selector_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": "0.8",
    "project_urls": {
        "repository": "https://github.com/carlosplanchon/parsel_get_selector_text.git"
    },
    "split_keywords": [
        "dom",
        " parsel",
        " scraping",
        " xpath"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1abc0c3dd84551275f2f90b1b8cb58a2d2813cecd160f3b8a4340846b8d3cb31",
                "md5": "d223658decd30952d16021cd7c12d6cb",
                "sha256": "fbb21a459aa95b7f16ff59ec2d9937c6c45c5c7c84aa31d58f1e4948d15002b7"
            },
            "downloads": -1,
            "filename": "parsel_get_selector_text-0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d223658decd30952d16021cd7c12d6cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4189,
            "upload_time": "2024-05-22T21:22:28",
            "upload_time_iso_8601": "2024-05-22T21:22:28.539205Z",
            "url": "https://files.pythonhosted.org/packages/1a/bc/0c3dd84551275f2f90b1b8cb58a2d2813cecd160f3b8a4340846b8d3cb31/parsel_get_selector_text-0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "693a027176495d31528bac69532e3ddc3f720425387e1e125eb512da8ee629b5",
                "md5": "5e194d1b884593fd068bd4d29754f939",
                "sha256": "9212a50197a841c0bff5ece1a30ff8a33f78981dae57f8352cda9a6700b43ad1"
            },
            "downloads": -1,
            "filename": "parsel_get_selector_text-0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "5e194d1b884593fd068bd4d29754f939",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3840,
            "upload_time": "2024-05-22T21:22:31",
            "upload_time_iso_8601": "2024-05-22T21:22:31.037119Z",
            "url": "https://files.pythonhosted.org/packages/69/3a/027176495d31528bac69532e3ddc3f720425387e1e125eb512da8ee629b5/parsel_get_selector_text-0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-22 21:22:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "carlosplanchon",
    "github_project": "parsel_get_selector_text",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "bs4",
            "specs": []
        },
        {
            "name": "ftfy",
            "specs": []
        },
        {
            "name": "parsel",
            "specs": []
        }
    ],
    "lcname": "parsel-get-selector-text"
}
        
Elapsed time: 3.41276s