![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Hext is a domain-specific language for extracting structured data from HTML. It can be thought of as a counterpart to templates, which are typically used by web developers to structure content on the web.
The following Hext template collects all hyperlinks and extracts the href and the clickable text.
<a href:link @text:title />
Hext does so by recursively trying to match every HTML element. In the case above, an element is required to have the tag a and an attribute called href. If the element matches, its attribute href and its textual representation are stored as link and title, respectively.
If the above Hext template is applied to this piece of HTML:
<body>
<a href="one.html"> Page 1</a>
<a href="two.html"> Page 2</a>
<a href="three.html">Page 3</a>
</body>
Hext will produce the following values:
{ "link": "one.html", "title": "Page 1" },
{ "link": "two.html", "title": "Page 2" },
{ "link": "three.html", "title": "Page 3" }
You can use this example in Hext’s live code editor. Visit Hext’s documentation and its section “How Hext Matches Elements” for a more thorough explanation.
This package includes:
The module exposes three interfaces:
html = hext.Html("<html>...</html>")
-> objectrule = hext.Rule("...")
-> objectrule.extract(html)
-> dictionary of {string -> string}rule.extract
has a second optional parameter max_searches
which is of type unsigned int. The search for matching elements is aborted after this limit is reached. The default is 0, which never aborts.import hext
import requests
import json
res = requests.get('https://news.ycombinator.com/')
res.raise_for_status()
# hext.Html's constructor expects a single argument
# containing an UTF-8 encoded string of HTML.
html = hext.Html(res.text)
# hext.Rule's constructor expects a single argument
# containing a Hext template.
# Throws an exception of type ValueError on invalid syntax.
rule = hext.Rule("""
<tr>
<td><span @text:rank /></td>
<td><a href:href @text:title /></td>
</tr>
<?tr>
<td>
<span @text:score />
<a @text:user />
<a:last-child @text:filter(/\d+/):comment_count />
</td>
</tr>""")
# hext.Rule.extract expects an argument of type hext.Html.
# Returns a list of dictionaries.
result = rule.extract(html)
# Print each dictionary as JSON
for map in result:
print(json.dumps(map, ensure_ascii=False,
separators=(',',':')))
Hext ships with a command line utility called htmlext, which applies Hext templates to HTML documents and outputs JSON.
htmlext - Extract structured content from HTML.
Usage:
htmlext [options] <hext-file> <html-file...>
Apply extraction rules from <hext-file> to each
<html-file> and print the captured content as JSON.
Options:
-x [ --hext ] <file> Add Hext from file
-i [ --html ] <file> Add HTML from file
-s [ --str ] <string> Add Hext from string
-c [ --compact ] Print one JSON object per line
-p [ --pretty ] Pretty-print JSON
-a [ --array ] Wrap results in a JSON array
-f [ --filter ] <key> Print values whose name matches <key>
-l [ --lint ] Do Hext syntax check
-h [ --help ] Print this help message
-V [ --version ] Print info and version
Ever wanted to watch the submissions on /r/videos in vlc? Well, take a look at this little guy right here:
htmlext \
-i <(wget -O- -o/dev/null "https://old.reddit.com/r/videos/") \
-s '<a class="title" href:x />' \
-f x \
| xargs vlc
Hext is released under the terms of the Apache License v2.0. The source code is hosted on Github. This binary package includes content authored by third parties:
FAQs
A module and command-line utility to extract structured data from HTML
We found that hext demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.