This commit is contained in:
ccppi 2024-07-01 11:39:33 +02:00
parent cdaf669e38
commit 8eb7f4d49e
3 changed files with 16 additions and 9 deletions

BIN
main

Binary file not shown.

View File

@ -26,7 +26,7 @@ try:
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref")) add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))
echo entry echo entry
entry.getEntryFromHtml(node) echo entry.getEntryFromHtml(node)
# echo node # echo node
# for a in node.findAll("a"): # for a in node.findAll("a"):
# if a.attrs.hasKey "href": # if a.attrs.hasKey "href":

View File

@ -10,11 +10,12 @@ type
html_context_tag* : string html_context_tag* : string
contains_string* : string contains_string* : string
attrs* : string attrs* : string
content* : string
type type
Entry* = object Entry* = object
desc* : seq[Descriptor] desc* : seq[Descriptor]
proc getEntryFromHtml*(entry : Entry, node : XmlNode) = proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
for i,desc in entry.desc: for i,desc in entry.desc:
echo("descriptor ",i," content: ",entry.desc[i]) echo("descriptor ",i," content: ",entry.desc[i])
let context = node.findAll(entry.desc[i].html_context_tag) let context = node.findAll(entry.desc[i].html_context_tag)
@ -24,17 +25,23 @@ proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
if entry.desc[i].attrs != "": if entry.desc[i].attrs != "":
if b.attrs.hasKey(entry.desc[i].attrs): if b.attrs.hasKey(entry.desc[i].attrs):
echo("found key [",entry.desc[i].attrs,"] in : ",b) echo("found key [",entry.desc[i].attrs,"] in : ",b)
echo("value: ",b.attrs[entry.desc[i].attrs])
if entry.desc[i].contains_string != "": if entry.desc[i].contains_string != "":
let content_txt = b.innerText() var content_txt :string = b.innerText()
echo(" and string(innerText): ",content_txt) echo(" and string(innerText): ",content_txt)
if content_txt.contains(entry.desc[i].contains_string): if content_txt.contains(entry.desc[i].contains_string):
echo("PATTERN MATCH") echo("PATTERN MATCH")
#return function entry.desc[i].content = content_txt
if entry.desc[i].contains_string != "": else:
echo("found string: ",b) entry.desc[i].content = b.attrs[entry.desc[i].attrs]
#check if b contains contains_string
#return function
elif entry.desc[i].contains_string != "":
var content_txt = b.innerText()
echo(" string(innerText): ",content_txt)
if content_txt.contains(entry.desc[i].contains_string):
echo("PATTERN MATCH")
entry.desc[i].content = content_txt
return entry
proc test() = proc test() =
var htmlnode : XmlNode var htmlnode : XmlNode
@ -44,6 +51,6 @@ proc test() =
echo entry echo entry
htmlnode = parseHtml(str_html) htmlnode = parseHtml(str_html)
entry.getEntryFromHtml(htmlnode) discard entry.getEntryFromHtml(htmlnode)
#test() #test()