This commit is contained in:
ccppi 2024-07-01 13:49:39 +02:00
parent 4d2b868b76
commit 605480dbfd
3 changed files with 28 additions and 6 deletions

BIN
main

Binary file not shown.

View File

@ -20,12 +20,11 @@ try:
var htmlnode: XmlNode
var entry : Entry
add(entry.desc,Descriptor(name : "alink", html_context_tag : "div", html_tag : "a",attrs : "href"))
add(entry.desc,Descriptor(name:"key_and_string_search",contains_string: "a",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"))
add(entry.desc,Descriptor(name : "", html_context_tag : "div",html_context_attrs : "class",html_context_key : "css-1d60yla ehesakb4", html_tag : "a",attrs : "href"))
#add(entry.desc,Descriptor(name:"key_and_string_search",contains_string: "a",html_context_tag : "div", html_tag : "a",attrs : "href"))
echo entry
echo("###########")
echo entry.getEntryFromHtml(node)
# echo node
# for a in node.findAll("a"):

View File

@ -8,6 +8,8 @@ type
name* : string
html_tag* : string
html_context_tag* : string
html_context_attrs* : string
html_context_key* : string
contains_string* : string
attrs* : string
content* : seq[string]
@ -16,9 +18,31 @@ type
desc* : seq[Descriptor]
proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
var
context : seq[XmlNode]
tmpContext : seq[XmlNode]
for i,desc in entry.desc:
context = @[] #clear sequences
tmpContext = @[]
echo("descriptor ",i," content: ",entry.desc[i])
let context = node.findAll(entry.desc[i].html_context_tag)
#filter context
if entry.desc[i].html_context_attrs == "":
context = node.findAll(entry.desc[i].html_context_tag)
else:
tmpContext = node.findAll(entry.desc[i].html_context_tag)
#filter by attributes
for i3,c in tmpContext:
echo("c: ",c.attrs, "i3: ", i3, "i: ", i, "len tmpContext: ",tmpContext.len())
if c.attrs.hasKey(entry.desc[i].html_context_attrs):
echo("HAS-Context_KEY: ",c.attrs)
if entry.desc[i].html_context_key != "":
if c.attrs[entry.desc[i].html_context_attrs] == entry.desc[i].html_context_key:
context.add(c)
echo("key_MATCH")
else:
context.add(c)
echo("out of for loop")
#end filter context
for a in context:
let subContext = a.findAll(entry.desc[0].html_tag)
for b in subContext:
@ -34,7 +58,6 @@ proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
entry.desc[i].content.add(content_txt)
else:
entry.desc[i].content.add(b.attrs[entry.desc[i].attrs])
elif entry.desc[i].contains_string != "":
var content_txt = b.innerText()
echo(" string(innerText): ",content_txt)