From dda3ed1b7d023a729f3c9ee32ad4c83248211f15 Mon Sep 17 00:00:00 2001 From: ccppi Date: Mon, 22 Jul 2024 14:20:29 +0200 Subject: [PATCH] vi fixes --- main.nim | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.nim b/main.nim index 8febf02..aa9e873 100644 --- a/main.nim +++ b/main.nim @@ -89,13 +89,12 @@ try: add(entry.desc,Descriptor(name : "test", html_context_tag : "div",html_context_attrs : "class",html_context_key : "css-19re50j", html_tag : "p",aattrs : "class",attrs_key : "css-svet6u")) #comparis stores part of the data in a script tag as a json-string, so we get that part: add(entry.desc,Descriptor(name : "script-json", html_context_tag : "script",html_context_attrs : "type",html_context_key : r"application/json", html_tag : "",aattrs : "",attrs_key : "")) - echo("###########") discard entry.getEntryFromHtml(node) - + #echo entry.desc[1].content[0] let jsonString = replaceWord(entry.desc[1].content[0],sub = r"\"",by = r""") let jsonNode = parseJson(jsonString) @@ -103,10 +102,25 @@ try: #echo "JSON Node:", jsonNode let field = jsonNode.getFields() - main_loop(jsonNode,0,searchString = "resultItems") + main_loop(jsonNode,0,searchString = "resultItems") #only for searching for the right key #-props-pageProps-initialResultData-resultItems + # + # + let results = jsonNode["props"]["pageProps"]["initialResultData"]["resultItems"] + let countInserat = len(jsonNode["props"]["pageProps"]["initialResultData"]["resultItems"]) + for i in 0..countInserat-1: + echo results[i]["AdId"] + echo results[i]["Title"] + echo results[i]["Price"] + echo results[i]["PropertyTypeText"] + echo results[i]["EssentialInformation"] + echo results[i]["Address"] + echo results[i]["Date"] + echo "-------------------------------" + + echo "number of inserats: ",countInserat echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["resultItems"][1]["Title"] - echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["adIds"][0] + echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["adIds"][1] finally: client.close()