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

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 either descendants() or children() methods

for i in rq.filter(r'table; tr').children()[:-2]:
    #"i"
    #   It has a set of functions for getting its properties:
    #       tag()           tag name
    #       insides()       string containing contents inside tag
    #       child_count()   count of children
    #       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

    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)

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

Uploaded Source

Built Distribution

reliq-0.0.5-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reliq-0.0.5.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.3

File hashes

Hashes for reliq-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ed0b370c3d91192f15c86668801596c817af35e2d98adb285ebb3e74aa4ff5c5
MD5 9ddbe3e3269651f900a364573a161385
BLAKE2b-256 ae8c8c149f2316634524afd795e6b1402bfef703e89e7a8f7a08f673a2e4f1b9

See more details on using hashes here.

File details

Details for the file reliq-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: reliq-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.3

File hashes

Hashes for reliq-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 511a7309ac67c0c5d20922a5cd8414907c68edf052ec6f012839b90e7d54f43a
MD5 a8335ab1e4db5b8aa14caf15ff2c6b87
BLAKE2b-256 76b6541fa5feaab92675fc989c2f5cecbbe0e2a3dd9874c23abed4f3dd43f50d

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