asdf
This commit is contained in:
parent
4d2b868b76
commit
605480dbfd
7
main.nim
7
main.nim
@ -20,12 +20,11 @@ try:
|
|||||||
var htmlnode: XmlNode
|
var htmlnode: XmlNode
|
||||||
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 : "", 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"))
|
#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"))
|
|
||||||
|
|
||||||
echo entry
|
echo entry
|
||||||
|
echo("###########")
|
||||||
echo entry.getEntryFromHtml(node)
|
echo entry.getEntryFromHtml(node)
|
||||||
# echo node
|
# echo node
|
||||||
# for a in node.findAll("a"):
|
# for a in node.findAll("a"):
|
||||||
|
27
scrap.nim
27
scrap.nim
@ -8,6 +8,8 @@ type
|
|||||||
name* : string
|
name* : string
|
||||||
html_tag* : string
|
html_tag* : string
|
||||||
html_context_tag* : string
|
html_context_tag* : string
|
||||||
|
html_context_attrs* : string
|
||||||
|
html_context_key* : string
|
||||||
contains_string* : string
|
contains_string* : string
|
||||||
attrs* : string
|
attrs* : string
|
||||||
content* : seq[string]
|
content* : seq[string]
|
||||||
@ -16,9 +18,31 @@ type
|
|||||||
desc* : seq[Descriptor]
|
desc* : seq[Descriptor]
|
||||||
|
|
||||||
proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
|
proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
|
||||||
|
var
|
||||||
|
context : seq[XmlNode]
|
||||||
|
tmpContext : seq[XmlNode]
|
||||||
for i,desc in entry.desc:
|
for i,desc in entry.desc:
|
||||||
|
context = @[] #clear sequences
|
||||||
|
tmpContext = @[]
|
||||||
echo("descriptor ",i," content: ",entry.desc[i])
|
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:
|
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:
|
||||||
@ -34,7 +58,6 @@ proc getEntryFromHtml*(entry :var Entry, node : XmlNode) : Entry =
|
|||||||
entry.desc[i].content.add(content_txt)
|
entry.desc[i].content.add(content_txt)
|
||||||
else:
|
else:
|
||||||
entry.desc[i].content.add(b.attrs[entry.desc[i].attrs])
|
entry.desc[i].content.add(b.attrs[entry.desc[i].attrs])
|
||||||
|
|
||||||
elif entry.desc[i].contains_string != "":
|
elif entry.desc[i].contains_string != "":
|
||||||
var content_txt = b.innerText()
|
var content_txt = b.innerText()
|
||||||
echo(" string(innerText): ",content_txt)
|
echo(" string(innerText): ",content_txt)
|
||||||
|
Loading…
Reference in New Issue
Block a user