perse converts HTML content into structured JSON data
Project description
Perse
Perse converts HTML
to JSON
using a mix of traditional html parsing and LLM based data extraction.
Features
It's core features includes:
- Identify important fields to extract from html
- Building a JSON schemas that handles nested fields
- Process html tokens and fill the JSON schema object
You can install Perse using pip:
pip install zf-perse
export PERSE_OPENAI_API_KEY="your-openai-api-key"
And run it from CLI:
perse --url https://google.com
Optimizations
It performs a few optimizations after fetching the html while preventing any accidental removal of important data.
These optimizations includes:
- Removal of styling, scripting and svg tags
- Collapsing Tags (e.g. divs) with only one child
Comparison
There are a few other libraries but none of them provide a solution for reliable data extraction from html.
HTML to JSON
html2json library is a simple html to json converter that doesn't handle nested fields, nor does it remove unnecessary tags.
When ran on exactly the same html, Perse provides a more structured and cleaner output and at least 50% less verbose output.
HTML to JSON | Perse |
---|---|
HTML to Markdown
Reader-LM is a language model that converts html to markdown. It doesn't provide a json output catering only to the reader mode which is not suitabel for data extraction, analysis and automations.
Usage
Process HTML content and get a Dictionary
html_content = "<html>...</html>"
json_dict = perse(html_content)
print(json_dict)
Process HTML content and get a JSON string
html_content = "<html>...</html>"
json_string = perses(html_content)
print(json_string)
Exclude specific tags from the JSON output
html_content = "<html>...</html>"
json_dict = perse(html_content, exclude_tags={"script", "style"})
print(json_dict)
Clean up the HTML content for side usage
html_content = "<html>...</html>"
clean_soup = simmer(html_content) # or use simmers for a string output
print(clean_soup.prettify())
Examples
Google's Homepage
$ perse --url https://google.com
{
"image": "/images/branding/googleg/1x/googleg_standard_color_128dp.png",
"title": "Google",
"search_form": {
"action": "/search",
"method": "GET",
"autocomplete": "off",
"query": "",
"buttons": [
{
"button_1": {
"label": "Google Search",
"value": "Google Search"
},
"button_2": {
"label": "I'm Feeling Lucky",
"value": "I'm Feeling Lucky"
}
}
]
}
}
Zeff Muks's Homepage
$ perse --url https://zeffmuks.com
{
"title": "Zeff Muks",
"description": "Antifragile Entropy Assassin \ud83e\udd77",
"og_data": {
"type": "website",
"title": "Zeff Muks",
"description": "Antifragile Entropy Assassin \ud83e\udd77",
"url": "https://zeffmuks.com/",
"image": "https://www.zeffmuks.com/images/ZeffMuks-1920.png",
"site_name": "Zeff Muks"
},
"twitter_data": {
"card": "summary_large_image",
"site": "@zeffmuks",
"title": "Zeff Muks",
"description": "Antifragile Entropy Assassin \ud83e\udd77",
"image": "https://www.zeffmuks.com/images/ZeffMuks-1920.png"
},
"user_section": {
"header": {
"profile_image_url": "/images/ZeffMuks-6912.png",
"title": "Antifragile Entropy Assassin \ud83e\udd77",
"signature": ""
},
"builds": [
{
"date": "08/30/2024",
"name": "Cursor Git",
"description": "Enhanced Git for Cursor AI Editor",
"download_link": "https://zf-static.s3.us-west-1.amazonaws.com/cursor-git-0.1.12.vsix",
"preview_image": "https://zf-static.s3.us-west-1.amazonaws.com/cursor-git-logo128.png",
"alternative_link": ""
},
{
"date": "08/18/2024",
"name": "PyZF",
"description": "Enhancements for Python",
"download_link": "https://pypi.org/project/PyZF",
"preview_image": "https://zf-static.s3.us-west-1.amazonaws.com/pyzf-logo128.png",
"alternative_link": ""
},
{
"date": "08/05/2024",
"name": "Xanthus",
"description": "X (formerly Twitter) Assistant",
"download_link": "https://pypi.org/project/zf-xanthus",
"preview_image": "https://zf-static.s3.us-west-1.amazonaws.com/xanthus-logo128.png",
"alternative_link": ""
},
{
"date": "07/24/2024",
"name": "Jenga",
"description": "Fast JSON5 Python Library",
"download_link": "https://pypi.org/project/zf-jenga",
"preview_image": "",
"alternative_link": ""
},
{
"date": "07/12/2024",
"name": "Pegasus",
"description": "Next Generation Tech Stack",
"download_link": "https://zf-static.s3.us-west-1.amazonaws.com/pegasus.zip",
"preview_image": "https://zf-static.s3.us-west-1.amazonaws.com/pegasus-logo128.png",
"alternative_link": ""
},
...
{
"date": "11/01/2023",
"name": "Z",
"description": "Next Generation Content Platform",
"download_link": "https://x.com/zeffmuks/status/1718507463321010429",
"preview_image": "https://zf-static.s3.us-west-1.amazonaws.com/z-logo128.png",
"alternative_link": "https://alpha.thez.ai/try"
}
]
}
}
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file zf_perse-1.0.0.tar.gz
.
File metadata
- Download URL: zf_perse-1.0.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17d749de6328c72472659e71e9676a51c3ff998c6b39ddf3df5b69e6d7fdd35 |
|
MD5 | 5eccf48ecce8ff27b000cc81a7c5e575 |
|
BLAKE2b-256 | 983a332ac67a807e28378ab071c077406708f3e5da690c8adba060cf3fb3c674 |
File details
Details for the file zf_perse-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: zf_perse-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2beb28cf2e87bc404e842befd90ae177c5fbacc3539bbbc5f2e7d9bbdb8d1899 |
|
MD5 | af357a680e3a18ca0a7cb70220794d45 |
|
BLAKE2b-256 | b99e43adf1dee2a44fab778be2cef86f40718251e470aa125da3dcfb94d04d3b |