rework
This commit is contained in:
parent
d4a3bf6f44
commit
93bdbf42c9
65
main.nim
65
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")
|
||||||
|
|
||||||
|
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 searchString == "" or node.contains(searchString):
|
||||||
|
stdout.write("\n")
|
||||||
|
echo "childs: "
|
||||||
|
for y in node.keys:
|
||||||
|
stdout.write ", " ,y," [", node[y].kind,"] \n"
|
||||||
|
do_another_loop(node,level+1,searchString,path & "-" & key)
|
||||||
|
#children of currentObj
|
||||||
|
|
||||||
|
proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "") =
|
||||||
|
if searchString == "" or node.contains(searchString):
|
||||||
|
echo "Array Elements: ", node.getElems()
|
||||||
|
echo "Array Length", node.len()
|
||||||
|
echo "WWWWWWWWWWWWWWW"
|
||||||
|
for b in node:
|
||||||
|
echo "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
||||||
|
do_another_loop(b,level+1,searchString,path & "-" & $node)
|
||||||
|
#if node[a].kind == JString:
|
||||||
|
#echo "String: ", node[a]
|
||||||
|
#stdout.write "\n"
|
||||||
|
|
||||||
|
proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
||||||
if node.len() > 0:
|
if node.len() > 0:
|
||||||
for a in node.keys:
|
if node.kind == JObject:
|
||||||
if node.kind == JObject:
|
for a in node.keys:
|
||||||
#for i in 0 .. level:
|
|
||||||
if searchString == "" or a.contains(searchString):
|
|
||||||
#for x in 0..level:
|
|
||||||
# stdout.write " "
|
|
||||||
stdout.write "|", path & "-" & a
|
|
||||||
if node[a].kind == JObject:
|
if node[a].kind == JObject:
|
||||||
stdout.write("\n")
|
do_loop(node[a],level,searchString,path, a)
|
||||||
do_another_loop(node[a],level+1,searchString,path & "-" & a)
|
elif node[a].kind == JArray:
|
||||||
else:
|
do_array_loop(node[a],level,searchString,path)
|
||||||
if searchString == "" or a.contains(searchString):
|
elif node.kind == JArray:
|
||||||
stdout.write " [", node[a].kind, "]"
|
do_array_loop(node,level,searchString,path)
|
||||||
stdout.write("\n")
|
|
||||||
if node[a].kind == JArray:
|
|
||||||
if searchString == "" or a.contains(searchString):
|
|
||||||
echo "Array Elements: ", node[a].getElems()
|
|
||||||
echo "Array Length", node[a].len()
|
|
||||||
echo "WWWWWWWWWWWWWWW"
|
|
||||||
for b in node[a]:
|
|
||||||
echo b
|
|
||||||
do_another_loop(b,level,searchString,path & "-" & a)
|
|
||||||
|
|
||||||
#stdout.write "\n"
|
|
||||||
else:
|
|
||||||
echo "\n--------"
|
|
||||||
|
|
||||||
|
|
||||||
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