Skip to main content

Parse JS variables from HTML markup

Project description

Markup Parser

Extract JS variables content from HTML markup

Codecov Build Status Versions Release

ENG

RU

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

ENG

Установка

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.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

markup_parser-0.1.2-cp39-cp39-macosx_10_15_x86_64.whl (9.1 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

File details

Details for the file markup-parser-0.1.2.tar.gz.

File metadata

  • Download URL: markup-parser-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.2

File hashes

Hashes for markup-parser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 312867beb8bfb3261acbd12c3e55626db2f86ab3230eda558eafe37f743e5681
MD5 3609c817f37b238422b8148795d9bbd0
BLAKE2b-256 2156eb33b855807305ccb66ca297ab9d02195bd11922e9a4f2662f1a3588928a

See more details on using hashes here.

File details

Details for the file markup_parser-0.1.2-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: markup_parser-0.1.2-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 9.1 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.2

File hashes

Hashes for markup_parser-0.1.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b8dc9e392e730cd240ecbda40275c9c2129df99931b7f4cb594327068d9a671c
MD5 0c44135d9c7560be6f3468307f47beb4
BLAKE2b-256 7be1b33c56f28903fc074d37decae3d10a799b84d08d84bac35fdad6c90c8078

See more details on using hashes here.

Supported by

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