implement tag searching

This commit is contained in:
2024-06-28 13:19:47 +02:00
parent fe35b44aa5
commit a706754ab4
4 changed files with 47 additions and 45 deletions

View File

@@ -3,6 +3,7 @@ import std/htmlparser
import std/xmltree
import std/strtabs
import std/os
import scrap
var client = newHttpClient()
var html: string
@@ -13,17 +14,23 @@ var url: string = readLine(stdin)
echo "given url is: ",url
try:
html = client.getContent(url)
let node = parseHtml(html)
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"
html = client.getContent(url)
let node = parseHtml(html)
var htmlnode: XmlNode
var entry : Entry
entry.name = Descriptor(html_context_tag : "div", html_tag : "a",attrs : "href")
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()