Skip to main content

Python ctypes bindings for reliq

Project description

reliq-python

A python module for reliq library.

Requirements

Installation

pip install reliq

Import

from reliq import reliq

Usage

from reliq import reliq, ReliqError

html = ""
with open('index.html','r') as f:
    html = f.read()

rq = reliq(html) #parse html
expr = reliq.expr(r"""
    div .user; {
        a href; {
            .name * l@[0] | "%i"
            .link * l@[0] | "%(href)v"
        },
        .score.u span .score,
        .info dl; {
            .key dt | "%i",
            .value dd | "%i"
        },
        .achievements.a li class=b>"achievement-" | "%i\n"
    }
""") #expressions can be compiled

users = []
links = []
images = []

#filter()
#   returns object holding list of results such object
#   behaves like an array, but can be converted to array with
#       self() - objects with lvl() 0
#       children() - objects with lvl() 1
#       descendants() - objects with lvl > 0
#       full() - same as indexing filter(), all objects

for i in rq.filter(r'table; tr').self()[:-2]:
    #"i"
    #   It has a set of functions for getting its properties:
    #       tag()           tag name
    #       insides()       string containing contents inside tag
    #       desc_count()   count of descendants
    #       lvl()           level in html structure
    #       attribsl()      number of attributes
    #       attribs()       returns dictionary of attributes

    if i.child_count() < 3 and i[0].tag() == "div":
        continue

    #objects can be accessed as an array which is the same
    #as array returned by descendants() method
    link = i[5].attribs()['href']
    if re.match('^https://$',href):
        links.append(link)
        continue

    #search() returns str, in this case expression is already compiled
    user = json.loads(i.search(expr))
    users.append(user)

#reliq objects have __str__ method
#get_data() returns data from which the html structure has been compiled

#if the second argument of filter() is True the returned
#object will use independent data, allowing garbage collector
#to free the previous unused data

#fsearch()
#   executes expression at parsing saving memory, and because
#   of that it supports only chain expressions i.e use of
#   grouping brackets and separating commas will throw an exception
for i in reliq.fsearch(r'ul; img src | "%(src)v\n"',html).split('\n')[:-1]:
    images.append(i)

try: #handle errors
    reliq.fsearch('p / /','<p></p>')
except ReliqError:
    print("error")

Projects using reliq

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

reliq-0.0.28.tar.gz (17.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

reliq-0.0.28-cp312-cp312-win_amd64.whl (146.3 kB view details)

Uploaded CPython 3.12Windows x86-64

reliq-0.0.28-cp312-cp312-manylinux2014_x86_64.whl (117.2 kB view details)

Uploaded CPython 3.12

reliq-0.0.28-cp312-cp312-macosx_14_0_arm64.whl (87.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

reliq-0.0.28-cp312-cp312-macosx_13_0_arm64.whl (91.5 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

reliq-0.0.28-cp310-cp310-manylinux2014_armv7l.whl (93.0 kB view details)

Uploaded CPython 3.10

reliq-0.0.28-cp310-cp310-manylinux2014_aarch64.whl (113.8 kB view details)

Uploaded CPython 3.10

File details

Details for the file reliq-0.0.28.tar.gz.

File metadata

  • Download URL: reliq-0.0.28.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for reliq-0.0.28.tar.gz
Algorithm Hash digest
SHA256 0d69e6162d1917a8945bfef4567ea73ff9ee3daa4bc0fa9988bfe60aa14b9f0c
MD5 bb473292c0e00d6a88ec70c33d514afd
BLAKE2b-256 b291cc309f93a4e9005c5aced7fff5209e680bf745c295964b5cbde1e3534492

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: reliq-0.0.28-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 146.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for reliq-0.0.28-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 05bda09e60353d1a0b2b1844f7e19494c80c656cf5729538e6df96e66e0f45e0
MD5 22eb91f7607f9fad66a31bee7d25a60a
BLAKE2b-256 bf18807dd05d9689c90c0e423a9ed4fbb754f0afd2f34c7e7cc00307924df38e

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for reliq-0.0.28-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d004e07217217eb34ac3f5b7dcc3e1f1b9c1121cc70206e204e2ff42cf712d97
MD5 c5f733fd41ec23505f0c86d506ba1566
BLAKE2b-256 ff07c0b86f1d71f768e0fb8447f4bb27b0467435d81bee72a5b03baccd1f8417

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for reliq-0.0.28-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5fd17cb46e8a640deedd4c672085e365dba89dba4626b62dbfd95583fb010519
MD5 71d19b420e27516b4a2208b2c98f8643
BLAKE2b-256 a417cf99ea88039b6473eff7468c683dcd7f3f40c2dff09de29eb462bcd56700

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for reliq-0.0.28-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 b54afd2e76a2bab613bc38da9bab9adf1accadef0ddb40afbd59960c08343db2
MD5 5439be02e00a4f7418ea3f94f5cb42cc
BLAKE2b-256 127280a9bf4b9bc01a95d47f0c3608fc6ac93959e429d861fb6262fdb6f47658

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp310-cp310-manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for reliq-0.0.28-cp310-cp310-manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 aab4d1c05ff618634902b18049bcace39af69fc85ab55fa59204cb9a1fa9eda6
MD5 c24f74b575d981f375acfb0504918883
BLAKE2b-256 c685ccd243381af366ffdcb31ee62e7d424afdaa8dbcb299613f2863c8c7dd1c

See more details on using hashes here.

File details

Details for the file reliq-0.0.28-cp310-cp310-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for reliq-0.0.28-cp310-cp310-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eb33625c4960dcd2d713ebd2badc1815b053668dbfd73e89503b7932c70a78f6
MD5 ed7415b7cf89f4a38a4fa56fbb8b33c1
BLAKE2b-256 256f2a553ecae9bb2245b31c83d8585f6350e22c0a26a01c8ea54249517f85cb

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