Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Convert a HTML webpage to JSON data using a template defined in JSON.
This package is available on PyPi. Just use pip install -U html2json
to install it. Then you can import it using from html2json import collect
.
The method is collect(html, template)
. html
is the HTML of page loaded as string, and template
is the JSON of template loaded as Python objects.
Note that the HTML must contain the root node, like <html>...</html>
or <div>...</div>
.
keyName: [selector, attr, [listOfRegexes]]
.
selector
is a CSS selector (supported by lxml).
null
, the root node itself is matched.null
is returned.attr
matches the attribute value. It can be null
to match either the inner text or the outer text when the inner text is empty.[listOfRegexes]
supports two forms of regex operations. The operations with in the list are executed sequentially.
s/regex/replacement/g
. g
is optional for multiple replacements./regex/
.For example:
{
"Color": ["head link:nth-of-type(1)", "href", ["/\\w+(?=\\.css)/"]],
}
{
"Cover": {
"URL": [".cover img", "src", []],
"Number of Favorites": [".cover .favorites", "value", []]
},
}
keyName: [subRoot, subTemplate]
can be used.
subRoot
a CSS selector of the new root for each sub entry.subTemplate
is a sub-template for each entry, recursively.For example, the previous example can be simplified as follow.
{
"Cover": [".cover", {
"URL": ["img", "src", []],
"Number of Favorites": [".favorites", "value", []]
}],
}
keyName: [[subRoot, subTemplate]]
. Please note the difference (surrounding [
and ]
) from the previous syntax above.
subRoot
is the CSS selector of the new root for each sub entry.subTemplate
is the sub-template for each entry, recursively.For example:
{
"Comments": [[".comments", {
"From": [".from", null, []],
"Content": [".content", null, []],
"Photos": [["img", {
"URL": ["", "src", []]
}]]
}]]
}
FAQs
Parsing HTML to JSON
We found that html2json 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.