Skip to main content

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������������������������������������������������������������������������������������������

������

������������������������������������������ ������������������������������ img.png

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

my_js_parser-0.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

my_js_parser-0.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for my_js_parser-0.5.tar.gz
Algorithm Hash digest
SHA256 b8c3dcf99e1e83349afabbd76e71a95838ff9f035c9cd5949419259eebdd2453
MD5 f0fce4e8056bb86bd49d05956dd82a6d
BLAKE2b-256 81ea148a362601126ccba2931bd85529ae8754df62a38610c3e7d53e20e2ce76

See more details on using hashes here.

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

Hashes for my_js_parser-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2800beb4002365741b7a3f4af0169d16db20d971edcaffd4e2c4fef1e692834c
MD5 6130141f0ce67ccb28c58c031595002e
BLAKE2b-256 51cbc1c9280ec0a4ddc2f52e5553e9e5b39916d98752536591fbc678c2b3d69b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page