mirror of
https://github.com/TelegramXPlus/beautifulparser
synced 2026-01-02 21:44:44 +00:00
No description
| .github/workflows | ||
| src | ||
| tests | ||
| .gitattributes | ||
| .gitignore | ||
| beautifulparser.nimble | ||
| LICENSE | ||
| README.md | ||
beautifulparser
beautifulparser is a (very) simple library for parsing HTML documents inspired by beautifulsoup4
Getting Started
nimble install beautifulparser
Usage
import std/htmlparser # to use loadHtml/parseHtml procedures
import beautifulparser
let html = loadHtml("input.html") # or parseHtml("<h1>Your html</h1>")
for i in html.findAllNodes("span", {"class": "my-custom-class"}):
echo i.innerText
Using tables
You can also use tables instead of arrays of tuples of strings (lol)
import std/[htmlparser, tables]
import beautifulparser
let html = loadHtml("input.html")
for i in html.findAllNodes("span", {"class": "my-custom-class"}.toTable()):
echo i.innerText
Get the first element
import std/htmlparser
import beautifulparser
let html = loadHtml("input.html")
let mySpan = html.findNode("span", {"class", "my-custom-class"})
if mySpan.isSome():
# implement your logic