av-ld_json_extractor
A lightweight Python library designed to extract ld+json from <script> tags within HTML documents
Installation
Using uv:
uv add av-ld_json_extractor
Quick Start
1. Extract JSON-LD Data from HTML
from selectolax.lexbor import LexborHTMLParser
from av_ld_json_extractor import ld_json_iter
html_content = """
<!DOCTYPE html>
<html>
<head>
<script type="application/ld+json">
{"@context": "[https://schema.org](https://schema.org)", "@type": "Organization", "name": "Example Corp"}
</script>
<script type="application/ld+json">
{"@type": "Product", "name": "Gaming Laptop", "price": 1200}
</script>
</head>
</html>
"""
parser = LexborHTMLParser(html_content)
for data in ld_json_iter(parser):
print(data)
# Output:
# {'@context': '[https://schema.org](https://schema.org)', '@type': 'Organization', 'name': 'Example Corp'}
# {'@type': 'Product', 'name': 'Gaming Laptop', 'price': 1200}
2. Find Specific @type (Objects & Lists)
from selectolax.lexbor import LexborHTMLParser
from av_ld_json_extractor import find_ld_json
html_content = """
<script type="application/ld+json">
[
{"@type": "BreadcrumbList", "itemListElement": []},
{"@type": "Product", "name": "Wireless Mouse", "price": 25}
]
</script>
"""
parser = LexborHTMLParser(html_content)
# Automatically searches inside both single JSON objects and array lists
product = find_ld_json("Product", parser)
print(product)
# Output:
# {'@type': 'Product', 'name': 'Wireless Mouse', 'price': 25}
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ld_json_extractor-0.1.5.tar.gz.
File metadata
- Download URL: ld_json_extractor-0.1.5.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24e9ed8dbe21485cc1286181f6bb7c32eca84314b59eba12660bf02e8666dbce
|
|
| MD5 |
6507ce128a6a81f5f3841d3e851fe98f
|
|
| BLAKE2b-256 |
31049c9c0ae01e3887fcdfb9bc3e914b5c6c476f21b6524c0eeeaf50d7592620
|
File details
Details for the file ld_json_extractor-0.1.5-py3-none-any.whl.
File metadata
- Download URL: ld_json_extractor-0.1.5-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fc3fc41c120b439c76a0c5acaa350286198b8e44be1fc1938fbcf80abd4841b
|
|
| MD5 |
c67390f58570ed11b4ee9d00b4d826dc
|
|
| BLAKE2b-256 |
4537c214501e33cce22fb2ada7346d20f2e7e70011a152028cc30e80e133dd79
|