html2object


Namehtml2object JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/boterop/html2object
SummaryTools to handle the CRUD of .html files as objects.
upload_time2024-05-17 03:23:44
maintainerNone
docs_urlNone
authorboterop
requires_python>=3.6
licenseNone
keywords html utils html_utils html_element html_parser html_writer html_reader html_crud html_object html_file html_utils.py html_element.py html_parser.py html_writer.py html_reader.py html_crud.py html_object.py html_file.py html2object html2object.py html2object.py
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Coverage Status](https://coveralls.io/repos/github/boterop/html2object/badge.svg?branch=main)](https://coveralls.io/github/boterop/html2object?branch=main)

# HTML 2 Object

Tools to handle the CRUD of .html files as objects.

## Install

```sh
pip install html2object
```

## Functions

- Parse your html file

  ```py
  html = open(<path>, "r").read("bin/gui/index.html")
  document = HtmlElement(html)
  ```

- Add attributes

  ```py
  document.add_attribute("class", "flex pt-2")
  ```

- Add children

  ```py
  p = HtmlElement(name="p").add_child("This is a text")
  document.add_child(p)
  ```

- Set new children

  ```py
  p = HtmlElement(name="p").add_child("This is a text")
  document.set_children([p])
  ```

- Get element by id

  ```py
  image = document.get_element_by_id("image_id")
  image.add_attribute("src", "image_url")
  ```

- Get elements by name

  ```py
  images = document.get_elements_by_name("image")
  for image in images:
    url_list.append(image.get_attribute("src"))
  ```

- Get elements by class name

  ```py
  theme_element = document.get_elements_by_class_name("radix-themes")
  for element in theme_element:
    print(f"Main color: {element.get_attribute('data-accent-color')}")
  ```

## Usage

This project provides a way to manipulate HTML files and update them dynamically. Here's how you can use it:

First, import the necessary classes from this project:

```sh
from html2object import HtmlElement
```

read your html file and:

#### Create an `HtmlElement()`

```sh
html = open(<path>, "r").read("bin/gui/index.html")
document = HtmlElement(html)
```

#### Create scripts

```sh
update_script = HtmlElement(name="script").add_child(
    "setInterval(() => reload(), 1500);"
)
document.add_child(update_script)
```

#### Create a div

```sh
p = HtmlElement(name="p", id="textID").add_chil("Text")
div = HtmlElement(name="div").add_child(p)
document.add_child(div)
```

#### Use Document functions like JS

```sh
text_element = document.get_element_by_id("textID")
strong = HtmlElement(name="strong").add_child("Strong text")
text_element.set_child([strong, "No strong text"])
```

### save the html file running

```sh
open(path, "w").write(str(document)).close()
```

## Local setup

Instructions on how to install and set up your project. Include any dependencies that need to be installed.

1. Clone the repository
2. Navigate to the project directory:

```sh
cd html2object
```

3. Create a virtual environment (optional but recommended):

```sh
python3 -m venv venv
```

4. Activate the virtual environment:

- For Windows:

```sh
venv\Scripts\activate
```

- For macOS and Linux:

```sh
source venv/bin/activate
```

5. Install the project dependencies:

```sh
pip install -r requirements.txt
```

That's it! Your project should now be installed and ready to use.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/boterop/html2object",
    "name": "html2object",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "html, utils, html_utils, html_element, html_parser, html_writer, html_reader, html_crud, html_object, html_file, html_utils.py, html_element.py, html_parser.py, html_writer.py, html_reader.py, html_crud.py, html_object.py, html_file.py, html2object, html2object.py, html2object.py",
    "author": "boterop",
    "author_email": "boterop22@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f5/28/f22104f1d02a40ad4862b956b4a82fed9ec64f4e59760b2ea1101a095a3b/html2object-1.1.0.tar.gz",
    "platform": null,
    "description": "[![Coverage Status](https://coveralls.io/repos/github/boterop/html2object/badge.svg?branch=main)](https://coveralls.io/github/boterop/html2object?branch=main)\n\n# HTML 2 Object\n\nTools to handle the CRUD of .html files as objects.\n\n## Install\n\n```sh\npip install html2object\n```\n\n## Functions\n\n- Parse your html file\n\n  ```py\n  html = open(<path>, \"r\").read(\"bin/gui/index.html\")\n  document = HtmlElement(html)\n  ```\n\n- Add attributes\n\n  ```py\n  document.add_attribute(\"class\", \"flex pt-2\")\n  ```\n\n- Add children\n\n  ```py\n  p = HtmlElement(name=\"p\").add_child(\"This is a text\")\n  document.add_child(p)\n  ```\n\n- Set new children\n\n  ```py\n  p = HtmlElement(name=\"p\").add_child(\"This is a text\")\n  document.set_children([p])\n  ```\n\n- Get element by id\n\n  ```py\n  image = document.get_element_by_id(\"image_id\")\n  image.add_attribute(\"src\", \"image_url\")\n  ```\n\n- Get elements by name\n\n  ```py\n  images = document.get_elements_by_name(\"image\")\n  for image in images:\n    url_list.append(image.get_attribute(\"src\"))\n  ```\n\n- Get elements by class name\n\n  ```py\n  theme_element = document.get_elements_by_class_name(\"radix-themes\")\n  for element in theme_element:\n    print(f\"Main color: {element.get_attribute('data-accent-color')}\")\n  ```\n\n## Usage\n\nThis project provides a way to manipulate HTML files and update them dynamically. Here's how you can use it:\n\nFirst, import the necessary classes from this project:\n\n```sh\nfrom html2object import HtmlElement\n```\n\nread your html file and:\n\n#### Create an `HtmlElement()`\n\n```sh\nhtml = open(<path>, \"r\").read(\"bin/gui/index.html\")\ndocument = HtmlElement(html)\n```\n\n#### Create scripts\n\n```sh\nupdate_script = HtmlElement(name=\"script\").add_child(\n    \"setInterval(() => reload(), 1500);\"\n)\ndocument.add_child(update_script)\n```\n\n#### Create a div\n\n```sh\np = HtmlElement(name=\"p\", id=\"textID\").add_chil(\"Text\")\ndiv = HtmlElement(name=\"div\").add_child(p)\ndocument.add_child(div)\n```\n\n#### Use Document functions like JS\n\n```sh\ntext_element = document.get_element_by_id(\"textID\")\nstrong = HtmlElement(name=\"strong\").add_child(\"Strong text\")\ntext_element.set_child([strong, \"No strong text\"])\n```\n\n### save the html file running\n\n```sh\nopen(path, \"w\").write(str(document)).close()\n```\n\n## Local setup\n\nInstructions on how to install and set up your project. Include any dependencies that need to be installed.\n\n1. Clone the repository\n2. Navigate to the project directory:\n\n```sh\ncd html2object\n```\n\n3. Create a virtual environment (optional but recommended):\n\n```sh\npython3 -m venv venv\n```\n\n4. Activate the virtual environment:\n\n- For Windows:\n\n```sh\nvenv\\Scripts\\activate\n```\n\n- For macOS and Linux:\n\n```sh\nsource venv/bin/activate\n```\n\n5. Install the project dependencies:\n\n```sh\npip install -r requirements.txt\n```\n\nThat's it! Your project should now be installed and ready to use.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Tools to handle the CRUD of .html files as objects.",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/boterop/html2object"
    },
    "split_keywords": [
        "html",
        " utils",
        " html_utils",
        " html_element",
        " html_parser",
        " html_writer",
        " html_reader",
        " html_crud",
        " html_object",
        " html_file",
        " html_utils.py",
        " html_element.py",
        " html_parser.py",
        " html_writer.py",
        " html_reader.py",
        " html_crud.py",
        " html_object.py",
        " html_file.py",
        " html2object",
        " html2object.py",
        " html2object.py"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4752db7cc4afb5222694dbbaa8e417f7b88023c0d5232a9da9f9da013c8b1a5",
                "md5": "ef689c0435aca3bb05e31aae16d7952e",
                "sha256": "d4a1dd262b69196d1c7e973075c8701bc98cd857bea4c90ee664bcb1724fc61a"
            },
            "downloads": -1,
            "filename": "html2object-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ef689c0435aca3bb05e31aae16d7952e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7556,
            "upload_time": "2024-05-17T03:23:42",
            "upload_time_iso_8601": "2024-05-17T03:23:42.923621Z",
            "url": "https://files.pythonhosted.org/packages/c4/75/2db7cc4afb5222694dbbaa8e417f7b88023c0d5232a9da9f9da013c8b1a5/html2object-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f528f22104f1d02a40ad4862b956b4a82fed9ec64f4e59760b2ea1101a095a3b",
                "md5": "de4ae482450084a8f483e9cca70c2393",
                "sha256": "9db40abc2c4beaddfa43cc1a2b12bceaea6fd8b4827e95ea8dd3a5726f4b86ee"
            },
            "downloads": -1,
            "filename": "html2object-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "de4ae482450084a8f483e9cca70c2393",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6291,
            "upload_time": "2024-05-17T03:23:44",
            "upload_time_iso_8601": "2024-05-17T03:23:44.543461Z",
            "url": "https://files.pythonhosted.org/packages/f5/28/f22104f1d02a40ad4862b956b4a82fed9ec64f4e59760b2ea1101a095a3b/html2object-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 03:23:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "boterop",
    "github_project": "html2object",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "html2object"
}
        
Elapsed time: 0.25766s