This commit is contained in:
ccppi 2024-07-22 14:20:29 +02:00
parent cdf0a06595
commit dda3ed1b7d

View File

@ -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")) 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: #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 : "")) 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("###########") echo("###########")
discard entry.getEntryFromHtml(node) discard entry.getEntryFromHtml(node)
#echo entry.desc[1].content[0] #echo entry.desc[1].content[0]
let jsonString = replaceWord(entry.desc[1].content[0],sub = r"\"",by = r""") let jsonString = replaceWord(entry.desc[1].content[0],sub = r"\"",by = r""")
let jsonNode = parseJson(jsonString) let jsonNode = parseJson(jsonString)
@ -103,10 +102,25 @@ try:
#echo "JSON Node:", jsonNode #echo "JSON Node:", jsonNode
let field = jsonNode.getFields() 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 #-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"]["resultItems"][1]["Title"]
echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["adIds"][0] echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["adIds"][1]
finally: finally:
client.close() client.close()