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

Uploaded Source

Built Distribution

markup_parser-0.1.1-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.1.tar.gz.

File metadata

  • Download URL: markup-parser-0.1.1.tar.gz
  • Upload date:
  • Size: 7.5 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.1.tar.gz
Algorithm Hash digest
SHA256 83e3d5fed5ce4b9789870907c7d3242ad41952b49e11374b085f0f9c7e5c50e5
MD5 68529dab94a07ba9ef47ed6b68ceb96a
BLAKE2b-256 93db12e9817fbee1ddf8af0ee3df6388a1445f62eea7627f9326520c2c7763c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: markup_parser-0.1.1-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.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 777ca6d51b0a003c8b5175896198f783978584c13148d49d0c5c72f54aca0d90
MD5 498e5b9526115d50550d625e0d3986c8
BLAKE2b-256 27972c1ec1b7ad9cea4d580ff30423a16ac9e4e501a34d885b20002a24c2e1cf

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