nim-basic/main.nim

42 lines
1.1 KiB
Nim

import std/httpclient
import std/htmlparser
import std/xmltree
import std/strtabs
import std/os
import scrap
var client = newHttpClient()
var html: string
#var node: XmlNode
echo "URL:"
var url: string = "https://www.comparis.ch/immobilien/marktplatz/lenzburg/mieten"#readLine(stdin)
echo "given url is: ",url
try:
html = client.getContent(url)
let node = parseHtml(html)
var htmlnode: XmlNode
var entry : Entry
add(entry.desc,Descriptor(name : "test", html_context_tag : "div",html_context_attrs : "class",html_context_key : "css-1wvv8q", html_tag : "a",aattrs : "href"))
#add(entry.desc,Descriptor(name:"key_and_string_search",contains_string: "a",html_context_tag : "div", html_tag : "a",attrs : "href"))
echo entry
echo("###########")
echo entry.getEntryFromHtml(node)
# echo node
# for a in node.findAll("a"):
# if a.attrs.hasKey "href":
# echo "striping"
# let (dir,filename,ext) = splitFile(a.attrs["href"])
# echo "found a link!",dir & "/" & filename
# else:
# echo "Key has no attribute href"
finally:
client.close()