nim-basic/scrap.nim

49 lines
1.2 KiB
Nim
Raw Normal View History

2024-06-27 11:55:39 +00:00
import std/htmlparser
import std/xmltree
import std/strtabs
2024-06-28 10:10:21 +00:00
type
2024-06-28 11:19:47 +00:00
Descriptor* = object
name* : string
html_tag* : string
html_context_tag* : string
contains_string* : string
attrs* : string
2024-06-27 10:02:25 +00:00
type
2024-06-28 11:19:47 +00:00
Entry* = object
2024-06-28 11:58:36 +00:00
name* : seq[Descriptor]
2024-06-28 10:10:21 +00:00
2024-06-28 11:19:47 +00:00
proc getEntryFromHtml*(entry : Entry, node : XmlNode) =
2024-06-28 11:58:36 +00:00
echo(entry.name[0])
let context = node.findAll(entry.name[0].html_context_tag)
2024-06-28 11:19:47 +00:00
for a in context:
2024-06-28 11:58:36 +00:00
let subContext = a.findAll(entry.name[0].html_tag)
2024-06-28 11:19:47 +00:00
for b in subContext:
echo(b)
2024-06-28 11:58:36 +00:00
if entry.name[0].attrs != "":
if b.attrs.hasKey(entry.name[0].attrs):
2024-06-28 11:19:47 +00:00
echo("found key")
2024-06-28 11:58:36 +00:00
if entry.name[0].contains_string != "":
2024-06-28 11:19:47 +00:00
echo(" and string")
#check if b contains contains_string
#return function
2024-06-28 11:58:36 +00:00
if entry.name[0].contains_string != "":
2024-06-28 11:19:47 +00:00
echo("found string")
#check if b contains contains_string
#return function
2024-06-27 10:02:25 +00:00
2024-06-27 11:55:39 +00:00
2024-06-27 10:02:25 +00:00
proc test() =
2024-06-27 11:55:39 +00:00
var htmlnode : XmlNode
var str_html : string
2024-06-27 10:02:25 +00:00
var entry: Entry
2024-06-28 11:58:36 +00:00
entry.name[0] = Descriptor(html_tag : "p", contains_string : "test_container")
2024-06-28 10:10:21 +00:00
echo entry
2024-06-27 10:02:25 +00:00
2024-06-27 11:55:39 +00:00
htmlnode = parseHtml(str_html)
2024-06-28 11:19:47 +00:00
entry.getEntryFromHtml(htmlnode)
2024-06-27 10:02:25 +00:00
2024-06-28 11:19:47 +00:00
#test()