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.4.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.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file my_js_parser-0.4.tar.gz.

File metadata

  • Download URL: my_js_parser-0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5ea1b1723fb7e7e4fdc29bb4a87aea8021c5e8c178c25b37eacc0e6f3c6908b3
MD5 cf53f5365e9facf979eed5935f7b972e
BLAKE2b-256 4b0ea9492a32471757a28dc2636d23885c4f01191acfff661a134746d09236df

See more details on using hashes here.

File details

Details for the file my_js_parser-0.4-py3-none-any.whl.

File metadata

  • Download URL: my_js_parser-0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e4fef0f823dac3b06042be5a19fc710f9b273a54fa0ee8721c197adab1761e9d
MD5 15f43043fa2fd6f50fa9a21dfd843859
BLAKE2b-256 70b389b51f8a302099ddc50ef136ace944aeb1f1c2a1a4a29b4ae584e16553ab

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