No project description provided
Project description
my_js_parser
my_js_parser ������������������������ JavaScript ��������������������������� JSON ��������� Python ��������������������������������������������������������������������� JSON ������������������������������������ JSON ���������
������
������������������������������������������
pip install my_js_parser
���������������
lxml==5.2.2
quickjs==1.19.4
������������
��� JavaScript ������������������������ JSON ������
my_js_parser ��������� extract_all_json ��������� parse_html ��������������������������������� JavaScript ������������������������������������ JSON ������
������������
������������
��������� my_js_parser.parser ��������� parse_html ���������
from my_js_parser.parser import parse_html
������������
parse_html(data: str) -> dict
- ������:
- data (str): ���������������html������������������������ JSON ������������js���������
- ���������:
- ��������������������������������������� JSON ��������������������������������������� JSON ������������������������������
������
from my_js_parser.parser import parse_html
# ������html
js_code = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
window.INITIAL_STATE={'user': 'JohnDoe', 'age': 30};
window.DATA={'products': ['apple', 'banana', 'orange'], 'prices': [1.2, 0.5, 0.75]};
(function(){ var script = document.currentScript; script.parentNode.removeChild(script); })();
</script>
</body>
</html>
"""
# ������������ JSON ������
json_data = parse_html(js_code)
print(f'parse result : {json_data}')
������������
parse result : {'INITIAL_STATE': {'user': 'JohnDoe', 'age': 30}, 'DATA': {'products': ['apple', 'banana', 'orange'], 'prices': [1.2, 0.5, 0.75]}, 'user': 'JohnDoe', 'age': 30, 'products': ['apple', 'banana', 'orange'], 'prices': [1.2, 0.5, 0.75]}
������������
������������
��������� my_js_parser.parser ��������� extract_all_json ���������
from my_js_parser.parser import extract_all_json
������������
extract_all_json(data: str) -> list[dict]
- ������:
- data (str): ���������������script������������������������ JSON ������������js������������������������������html������������������������������������������������������������������������������������������������������������������
- ���������:
- ��������������������������������������� JSON ��� LIST ��������������������� JSON ������������������������������
������
from my_js_parser.parser import extract_all_json
# ������������������������������ JSON ��������� JavaScript ������
js_code = """
window.INITIAL_STATE={'user': 'JohnDoe', 'age': 30};
window.DATA={'products': ['apple', 'banana', 'orange'], 'prices': [1.2, 0.5, 0.75]};
(function(){ var script = document.currentScript; script.parentNode.removeChild(script); })();
"""
# ������������ JSON ������
json_parts = extract_all_json(js_code)
# ������������������ JSON ������
for i, json_part in enumerate(json_parts):
print(f"JSON {i + 1}: {json_part}")
������������
JSON 1: {'user': 'JohnDoe', 'age': 30}
JSON 2: {'products': ['apple', 'banana', 'orange'], 'prices': [1.2, 0.5, 0.75]}
������
- ���������������������������������������quickjs ���������js��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� from lxml import etree ������������������script���������������������������������������������������list������������������������������������������������������������������������������������������
������
������������������������������������������
������������������������������
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
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 my_js_parser-0.5.tar.gz.
File metadata
- Download URL: my_js_parser-0.5.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8c3dcf99e1e83349afabbd76e71a95838ff9f035c9cd5949419259eebdd2453
|
|
| MD5 |
f0fce4e8056bb86bd49d05956dd82a6d
|
|
| BLAKE2b-256 |
81ea148a362601126ccba2931bd85529ae8754df62a38610c3e7d53e20e2ce76
|
File details
Details for the file my_js_parser-0.5-py3-none-any.whl.
File metadata
- Download URL: my_js_parser-0.5-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2800beb4002365741b7a3f4af0169d16db20d971edcaffd4e2c4fef1e692834c
|
|
| MD5 |
6130141f0ce67ccb28c58c031595002e
|
|
| BLAKE2b-256 |
51cbc1c9280ec0a4ddc2f52e5553e9e5b39916d98752536591fbc678c2b3d69b
|