Tools to handle the CRUD of .html files as objects.
Project description
HTML 2 Object
Tools to handle the CRUD of .html files as objects.
Install
pip install html2object
Functions
-
Parse your html file
html = open(<path>, "r").read("bin/gui/index.html") document = HtmlElement(html)
-
Add attributes
document.add_attribute("class", "flex pt-2")
-
Add children
p = HtmlElement(name="p").add_child("This is a text") document.add_child(p)
-
Set new children
p = HtmlElement(name="p").add_child("This is a text") document.set_children([p])
-
Get element by id
image = document.get_element_by_id("image_id") image.add_attribute("src", "image_url")
-
Get element by id
images = document.get_elements_by_name("image") for image in images: url_list.append(image.get_attribute("src"))
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:
from html2object import HtmlElement
read your html file and:
Create an HtmlElement()
html = open(<path>, "r").read("bin/gui/index.html")
document = HtmlElement(html)
Create scripts
update_script = HtmlElement(name="script").add_child(
"setInterval(() => reload(), 1500);"
)
document.add_child(update_script)
Create a div
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
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
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.
- Clone the repository
- Navigate to the project directory:
cd html2object
- Create a virtual environment (optional but recommended):
python3 -m venv venv
- Activate the virtual environment:
- For Windows:
venv\Scripts\activate
- For macOS and Linux:
source venv/bin/activate
- Install the project dependencies:
pip install -r requirements.txt
That's it! Your project should now be installed and ready to use.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
html2object-1.0.0.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for html2object-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd8710d9a88bac7af6c7543936532d2e8f53065d9e7e781e2f0bac1ac8c4ae5 |
|
MD5 | a6dca73a4024f84295c38c2d95cb79b7 |
|
BLAKE2b-256 | f7c6c8773fa2ebabd06e765f56623da2653f79b2c9a3bbb97b5e0581eff5c0a0 |