rework
This commit is contained in:
parent
d4a3bf6f44
commit
93bdbf42c9
59
main.nim
59
main.nim
@ -8,37 +8,44 @@ import std/json
|
|||||||
import std/strutils
|
import std/strutils
|
||||||
var client = newHttpClient()
|
var client = newHttpClient()
|
||||||
var html: string
|
var html: string
|
||||||
#var node: XmlNode
|
|
||||||
|
|
||||||
proc do_another_loop( node : JsonNode, level : int, searchString : string = "",path :string = "H") =
|
proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H")
|
||||||
if node.len() > 0:
|
|
||||||
for a in node.keys:
|
proc do_loop[T](node: T,level : int, searchString : string = "", path: string = "", key : string) =
|
||||||
|
if searchString == "" or node.contains(searchString):
|
||||||
|
stdout.write "|", path & "-" & key
|
||||||
|
#children of currentObj
|
||||||
if node.kind == JObject:
|
if node.kind == JObject:
|
||||||
#for i in 0 .. level:
|
if searchString == "" or node.contains(searchString):
|
||||||
if searchString == "" or a.contains(searchString):
|
|
||||||
#for x in 0..level:
|
|
||||||
# stdout.write " "
|
|
||||||
stdout.write "|", path & "-" & a
|
|
||||||
if node[a].kind == JObject:
|
|
||||||
stdout.write("\n")
|
stdout.write("\n")
|
||||||
do_another_loop(node[a],level+1,searchString,path & "-" & a)
|
echo "childs: "
|
||||||
else:
|
for y in node.keys:
|
||||||
if searchString == "" or a.contains(searchString):
|
stdout.write ", " ,y," [", node[y].kind,"] \n"
|
||||||
stdout.write " [", node[a].kind, "]"
|
do_another_loop(node,level+1,searchString,path & "-" & key)
|
||||||
stdout.write("\n")
|
#children of currentObj
|
||||||
if node[a].kind == JArray:
|
|
||||||
if searchString == "" or a.contains(searchString):
|
proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "") =
|
||||||
echo "Array Elements: ", node[a].getElems()
|
if searchString == "" or node.contains(searchString):
|
||||||
echo "Array Length", node[a].len()
|
echo "Array Elements: ", node.getElems()
|
||||||
|
echo "Array Length", node.len()
|
||||||
echo "WWWWWWWWWWWWWWW"
|
echo "WWWWWWWWWWWWWWW"
|
||||||
for b in node[a]:
|
for b in node:
|
||||||
echo b
|
echo "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
||||||
do_another_loop(b,level,searchString,path & "-" & a)
|
do_another_loop(b,level+1,searchString,path & "-" & $node)
|
||||||
|
#if node[a].kind == JString:
|
||||||
|
#echo "String: ", node[a]
|
||||||
#stdout.write "\n"
|
#stdout.write "\n"
|
||||||
else:
|
|
||||||
echo "\n--------"
|
|
||||||
|
|
||||||
|
proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
||||||
|
if node.len() > 0:
|
||||||
|
if node.kind == JObject:
|
||||||
|
for a in node.keys:
|
||||||
|
if node[a].kind == JObject:
|
||||||
|
do_loop(node[a],level,searchString,path, a)
|
||||||
|
elif node[a].kind == JArray:
|
||||||
|
do_array_loop(node[a],level,searchString,path)
|
||||||
|
elif node.kind == JArray:
|
||||||
|
do_array_loop(node,level,searchString,path)
|
||||||
|
|
||||||
echo "URL:"
|
echo "URL:"
|
||||||
var url: string = "https://www.comparis.ch/immobilien/marktplatz/lenzburg/mieten?page=2"#readLine(stdin)
|
var url: string = "https://www.comparis.ch/immobilien/marktplatz/lenzburg/mieten?page=2"#readLine(stdin)
|
||||||
@ -68,7 +75,7 @@ try:
|
|||||||
#echo "JSON Node:", jsonNode
|
#echo "JSON Node:", jsonNode
|
||||||
#echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr()
|
#echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr()
|
||||||
let field = jsonNode.getFields()
|
let field = jsonNode.getFields()
|
||||||
do_another_loop(jsonNode,0,searchString = "resultItems")
|
do_another_loop(jsonNode,0,searchString = "")
|
||||||
|
|
||||||
#echo "resultitem", jsonNode["resultItems"]
|
#echo "resultitem", jsonNode["resultItems"]
|
||||||
# for a in jsonNode.keys:
|
# for a in jsonNode.keys:
|
||||||
|
Loading…
Reference in New Issue
Block a user