implement pattern matching (substring)

This commit is contained in:
ccppi 2024-07-01 10:14:01 +02:00
parent b782ea43f2
commit cdaf669e38
3 changed files with 7 additions and 5 deletions

BIN
main

Binary file not shown.

View File

@ -21,7 +21,7 @@ try:
var entry : Entry var entry : Entry
add(entry.desc,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.desc,Descriptor(name:"anotherlin",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 : "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:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))

View File

@ -1,6 +1,7 @@
import std/htmlparser import std/htmlparser
import std/xmltree import std/xmltree
import std/strtabs import std/strtabs
import std/strutils
type type
Descriptor* = object Descriptor* = object
@ -20,13 +21,14 @@ proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
for a in context: for a in context:
let subContext = a.findAll(entry.desc[0].html_tag) let subContext = a.findAll(entry.desc[0].html_tag)
for b in subContext: for b in subContext:
echo(b)
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) echo("found key [",entry.desc[i].attrs,"] in : ",b)
if entry.desc[i].contains_string != "": if entry.desc[i].contains_string != "":
echo(" and string: ",b) let content_txt = b.innerText()
#check if b contains contains_string echo(" and string(innerText): ",content_txt)
if content_txt.contains(entry.desc[i].contains_string):
echo("PATTERN MATCH")
#return function #return function
if entry.desc[i].contains_string != "": if entry.desc[i].contains_string != "":
echo("found string: ",b) echo("found string: ",b)