implement pattern matching (substring)
This commit is contained in:
parent
b782ea43f2
commit
cdaf669e38
2
main.nim
2
main.nim
@ -21,7 +21,7 @@ try:
|
||||
var entry : Entry
|
||||
|
||||
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 : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))
|
||||
|
||||
|
10
scrap.nim
10
scrap.nim
@ -1,6 +1,7 @@
|
||||
import std/htmlparser
|
||||
import std/xmltree
|
||||
import std/strtabs
|
||||
import std/strutils
|
||||
|
||||
type
|
||||
Descriptor* = object
|
||||
@ -20,13 +21,14 @@ proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
|
||||
for a in context:
|
||||
let subContext = a.findAll(entry.desc[0].html_tag)
|
||||
for b in subContext:
|
||||
echo(b)
|
||||
if 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 != "":
|
||||
echo(" and string: ",b)
|
||||
#check if b contains contains_string
|
||||
let content_txt = 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)
|
||||
|
Loading…
Reference in New Issue
Block a user