sequence iterate description
This commit is contained in:
parent
6159f5d218
commit
b782ea43f2
7
main.nim
7
main.nim
@ -20,8 +20,11 @@ try:
|
|||||||
var htmlnode: XmlNode
|
var htmlnode: XmlNode
|
||||||
var entry : Entry
|
var entry : Entry
|
||||||
|
|
||||||
add(entry.name,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.name,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 : "div", html_tag : "a",attrs : "href"))
|
||||||
|
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))
|
||||||
|
|
||||||
echo entry
|
echo entry
|
||||||
entry.getEntryFromHtml(node)
|
entry.getEntryFromHtml(node)
|
||||||
# echo node
|
# echo node
|
||||||
|
27
scrap.nim
27
scrap.nim
@ -11,26 +11,25 @@ type
|
|||||||
attrs* : string
|
attrs* : string
|
||||||
type
|
type
|
||||||
Entry* = object
|
Entry* = object
|
||||||
name* : seq[Descriptor]
|
desc* : seq[Descriptor]
|
||||||
|
|
||||||
proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
|
proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
|
||||||
echo(entry.name[0])
|
for i,desc in entry.desc:
|
||||||
|
echo("descriptor ",i," content: ",entry.desc[i])
|
||||||
let context = node.findAll(entry.name[0].html_context_tag)
|
let context = node.findAll(entry.desc[i].html_context_tag)
|
||||||
for a in context:
|
for a in context:
|
||||||
|
let subContext = a.findAll(entry.desc[0].html_tag)
|
||||||
let subContext = a.findAll(entry.name[0].html_tag)
|
|
||||||
for b in subContext:
|
for b in subContext:
|
||||||
echo(b)
|
echo(b)
|
||||||
if entry.name[0].attrs != "":
|
if entry.desc[i].attrs != "":
|
||||||
if b.attrs.hasKey(entry.name[0].attrs):
|
if b.attrs.hasKey(entry.desc[i].attrs):
|
||||||
echo("found key")
|
echo("found key: ",entry.desc[i].attrs)
|
||||||
if entry.name[0].contains_string != "":
|
if entry.desc[i].contains_string != "":
|
||||||
echo(" and string")
|
echo(" and string: ",b)
|
||||||
#check if b contains contains_string
|
#check if b contains contains_string
|
||||||
#return function
|
#return function
|
||||||
if entry.name[0].contains_string != "":
|
if entry.desc[i].contains_string != "":
|
||||||
echo("found string")
|
echo("found string: ",b)
|
||||||
#check if b contains contains_string
|
#check if b contains contains_string
|
||||||
#return function
|
#return function
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ proc test() =
|
|||||||
var htmlnode : XmlNode
|
var htmlnode : XmlNode
|
||||||
var str_html : string
|
var str_html : string
|
||||||
var entry: Entry
|
var entry: Entry
|
||||||
entry.name[0] = Descriptor(html_tag : "p", contains_string : "test_container")
|
entry.desc[0] = Descriptor(html_tag : "p", contains_string : "test_container")
|
||||||
echo entry
|
echo entry
|
||||||
|
|
||||||
htmlnode = parseHtml(str_html)
|
htmlnode = parseHtml(str_html)
|
||||||
|
Loading…
Reference in New Issue
Block a user