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 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
#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
Release history Release notifications | RSS feed
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.10.tar.gz
(69.8 kB
view details)
Built Distribution
reliq-0.0.10-py3-none-any.whl
(67.6 kB
view details)
File details
Details for the file reliq-0.0.10.tar.gz
.
File metadata
- Download URL: reliq-0.0.10.tar.gz
- Upload date:
- Size: 69.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f110bdfccd3817648ccae2616a905a13d9123f88b6c1da1bcb54a41eb558178 |
|
MD5 | 0d76c92683c210c2a98b47fab0f4123b |
|
BLAKE2b-256 | e8b6ca05a8c067baa3c7a66ec864c03c8331a75ef32e9a1003e6a8f426d76e1b |
File details
Details for the file reliq-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: reliq-0.0.10-py3-none-any.whl
- Upload date:
- Size: 67.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07c48d9f9a3543c246c177db5473fffd8ff216aa12b0c684abe3401c6e53817c |
|
MD5 | 7370eb6f22e270466d8ad2a62de8f676 |
|
BLAKE2b-256 | 43e64ecda66111c394582aab5c9a8e084784d502c3ef1ba4cd8f0aa8e1eed338 |