43 lines
1.1 KiB
Nim
43 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 = 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 : "alink", html_context_tag : "div", html_tag : "a",attrs : "href"))
|
|
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "div", html_tag : "a",attrs : "href"))
|
|
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "div", html_tag : "a",attrs : "href"))
|
|
add(entry.desc,Descriptor(name:"anotherlin",html_context_tag : "didfgv", html_tag : "sdfga",attrs : "hdsfgref"))
|
|
|
|
echo entry
|
|
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()
|
|
|
|
|
|
|