Parse JS variables from HTML markup
Project description
Markup Parser
Extract JS variables content from HTML markup
ENG
Installation
pip install markup-parser
Usage
Parse variable from html text:
Test content
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
</body>
<script>
let test_variable = 'You found me';
</script>
</html>
import requests
from markup_parser import var_from_html
# Fetch html content by get request
html_text = requests.get('http://test.html').text
var_from_html(html_text, 'test_variable')
# Parse from file
var_from_html(open('test.html').read(), 'test_variable')
# >>> You found me
Parse variable from url:
* This variant not recommended if you need to specify custom headers, this feature may be added in future release
Test content
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
</body>
<script>
let test_variable = 'You found me again!';
</script>
</html>
from markup_parser import var_from_url
var_from_url('http://test.page', 'test_variable')
# >>> You found me again!
RU
Установка
pip markup-parser
Примеры использования
Получить значение переменной из html разметки:
Пример html страницы
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
</body>
<script>
let test_variable = 'You found me';
</script>
</html>
import requests
from markup_parser import var_from_html
# Получить html разметку с помощью get запроса
html_text = requests.get('http://test.html').text
var_from_html(html_text, 'test_variable')
# Прочитать из файла
var_from_html(open('test.html').read(), 'test_variable')
# >>> You found me
Получить значение переменной по ссылке:
* На данный момент этот вариант не рекомендуется если вам необходимы специфичные заголовки, эта функция может появтися в будущих релизах
Пример html страницы
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
</body>
<script>
let test_variable = 'You found me again!';
</script>
</html>
from markup_parser import var_from_url
var_from_url('http://test.page', 'test_variable')
# >>> You found me again!
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
markup_parser-0.1.3.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file markup_parser-0.1.3.tar.gz
.
File metadata
- Download URL: markup_parser-0.1.3.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b3b193fc6b63952bcece930fb9f9b4a414773d8cc4f458f97a13582fba677c |
|
MD5 | 69c2326df87535dab38449d54154a8a3 |
|
BLAKE2b-256 | b64be66b2d6efc8127ae6ab7c9d17b7916e5f5149ce5ae0b130c39848debdda2 |
File details
Details for the file markup_parser-0.1.3-cp39-cp39-macosx_12_0_arm64.whl
.
File metadata
- Download URL: markup_parser-0.1.3-cp39-cp39-macosx_12_0_arm64.whl
- Upload date:
- Size: 7.5 MB
- Tags: CPython 3.9, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaa9a841861788b9251a1cd602c6008038a4d81d608c03dfe606c10300d34b9f |
|
MD5 | c73b70f468ca2a18943df2821201862f |
|
BLAKE2b-256 | c0c2b1c2c971737dc5aa472f929c94cbcfcb92eed625126418d54df8f10d7f5f |