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 unpack() method

#result can be accessed like an array
for i in rq.filter(r'table; tr')[:-2]:
    #"i"
    #   also can be accessed as an array of its children
    #   and it also works with unpack().
    #   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
    
    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.2.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

reliq-0.0.2-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reliq-0.0.2.tar.gz
  • Upload date:
  • Size: 41.9 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.2.tar.gz
Algorithm Hash digest
SHA256 fb4013a4c76c4928fe78338189fbc275417b65701073a64b8d1ffa9f8e23fe2a
MD5 16b778ab891bc3c1fd67df4fa31c87b6
BLAKE2b-256 075d49adbdde30fdb4b5fc2d6f03cc9a3a7a5b136f92201bd3880c4100715e0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reliq-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2532dd7cdceff428bed2a3a74ad17b2f63deb4ebc9e487db6a68994e9e4dab85
MD5 c38e898dad9ece38a209dacbd0a3a301
BLAKE2b-256 551cf8f1d150ec7bf39a00fa96a636487cb8c08f1a68ca9d73e94f61f0561d37

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