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"))
echo entry
entry.getEntryFromHtml(node)
echo entry.getEntryFromHtml(node)
# echo node
# for a in node.findAll("a"):
# if a.attrs.hasKey "href":

View File

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