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

Uploaded Source

Built Distribution

markup_parser-0.1.0-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.0.tar.gz.

File metadata

  • Download URL: markup-parser-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 6f2cc72b6ebccd2a85ac4c73a94924c418df395292a18b0ea50b6e18d670812e
MD5 23d885d6caf4dc2bc4eccab60f2a7a1d
BLAKE2b-256 cfa609ba749becae1d38df2f4a076e3ad6c4a4988e89a0487fd4e2c471c6f50a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: markup_parser-0.1.0-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.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 42edfbd820a203ac572d66431a22274b9faa916f1f6b8a9c3cfa4233393a7c5a
MD5 3067a638b004b554418b769a7d166b19
BLAKE2b-256 87c88385585e7270518d3f53762263cc2e0f4ce1d1732a736be607338b2ad5b0

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