asdf
This commit is contained in:
23
scrap.nim
23
scrap.nim
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user