sequence iterate description

This commit is contained in:
ccppi 2024-07-01 09:55:25 +02:00
parent 6159f5d218
commit b782ea43f2
3 changed files with 25 additions and 23 deletions

BIN
main

Binary file not shown.

View File

@ -20,8 +20,11 @@ try:
var htmlnode: XmlNode var htmlnode: XmlNode
var entry : Entry var entry : Entry
add(entry.name,Descriptor(name : "alink", html_context_tag : "div", html_tag : "a",attrs : "href")) add(entry.desc,Descriptor(name : "alink", html_context_tag : "div", html_tag : "a",attrs : "href"))
add(entry.name,Descriptor(name:"anotherlin",html_context_tag : "div", html_tag : "a",attrs : "href")) add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "div", html_tag : "a",attrs : "href"))
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "div", html_tag : "a",attrs : "href"))
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))
echo entry echo entry
entry.getEntryFromHtml(node) entry.getEntryFromHtml(node)
# echo node # echo node

View File

@ -11,35 +11,34 @@ type
attrs* : string attrs* : string
type type
Entry* = object Entry* = object
name* : seq[Descriptor] desc* : seq[Descriptor]
proc getEntryFromHtml*(entry : Entry, node : XmlNode) = proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
echo(entry.name[0]) for i,desc in entry.desc:
echo("descriptor ",i," content: ",entry.desc[i])
let context = node.findAll(entry.name[0].html_context_tag) let context = node.findAll(entry.desc[i].html_context_tag)
for a in context: for a in context:
let subContext = a.findAll(entry.desc[0].html_tag)
let subContext = a.findAll(entry.name[0].html_tag) for b in subContext:
for b in subContext: echo(b)
echo(b) if entry.desc[i].attrs != "":
if entry.name[0].attrs != "": if b.attrs.hasKey(entry.desc[i].attrs):
if b.attrs.hasKey(entry.name[0].attrs): echo("found key: ",entry.desc[i].attrs)
echo("found key") if entry.desc[i].contains_string != "":
if entry.name[0].contains_string != "": echo(" and string: ",b)
echo(" and string") #check if b contains contains_string
#check if b contains contains_string #return function
#return function if entry.desc[i].contains_string != "":
if entry.name[0].contains_string != "": echo("found string: ",b)
echo("found string") #check if b contains contains_string
#check if b contains contains_string #return function
#return function
proc test() = proc test() =
var htmlnode : XmlNode var htmlnode : XmlNode
var str_html : string var str_html : string
var entry: Entry var entry: Entry
entry.name[0] = Descriptor(html_tag : "p", contains_string : "test_container") entry.desc[0] = Descriptor(html_tag : "p", contains_string : "test_container")
echo entry echo entry
htmlnode = parseHtml(str_html) htmlnode = parseHtml(str_html)