48 lines
1.3 KiB
Nim
48 lines
1.3 KiB
Nim
import std/htmlparser
|
|
import std/xmltree
|
|
import std/strtabs
|
|
|
|
type
|
|
Descriptor* = object
|
|
name* : string
|
|
html_tag* : string
|
|
html_context_tag* : string
|
|
contains_string* : string
|
|
attrs* : string
|
|
type
|
|
Entry* = object
|
|
desc* : seq[Descriptor]
|
|
|
|
proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
|
|
for i,desc in entry.desc:
|
|
echo("descriptor ",i," content: ",entry.desc[i])
|
|
let context = node.findAll(entry.desc[i].html_context_tag)
|
|
for a in context:
|
|
let subContext = a.findAll(entry.desc[0].html_tag)
|
|
for b in subContext:
|
|
echo(b)
|
|
if entry.desc[i].attrs != "":
|
|
if b.attrs.hasKey(entry.desc[i].attrs):
|
|
echo("found key: ",entry.desc[i].attrs)
|
|
if entry.desc[i].contains_string != "":
|
|
echo(" and string: ",b)
|
|
#check if b contains contains_string
|
|
#return function
|
|
if entry.desc[i].contains_string != "":
|
|
echo("found string: ",b)
|
|
#check if b contains contains_string
|
|
#return function
|
|
|
|
|
|
proc test() =
|
|
var htmlnode : XmlNode
|
|
var str_html : string
|
|
var entry: Entry
|
|
entry.desc[0] = Descriptor(html_tag : "p", contains_string : "test_container")
|
|
echo entry
|
|
|
|
htmlnode = parseHtml(str_html)
|
|
entry.getEntryFromHtml(htmlnode)
|
|
|
|
#test()
|