nim-basic/scrap.nim

54 lines
1.3 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
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-27 11:55:39 +00:00
Entry = object
2024-06-28 10:10:21 +00:00
name, tag, description, link, category : Descriptor
proc setDescriptor(desc : var Descriptor, descToChange : string, value : string) =
case descToChange:
of "name":
desc.name = value
of "html_tag":
desc.html_tag = value
of "html_context_tag":
desc.html_context_tag = value
of "contains_string":
desc.contains_string = value
of "attrs":
desc.attrs = value
#proc newEntry() : Entry =
# newDescriptor()
2024-06-27 10:02:25 +00:00
2024-06-27 11:55:39 +00:00
proc getEntryFromHtml(entry : Entry, node : XmlNode) =
2024-06-27 10:02:25 +00:00
echo(entry.description)
2024-06-28 10:10:21 +00:00
var childrens = node.findAll(entry.name.html_tag)
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 10:10:21 +00:00
# entry = Entry(name : "testname",description : "testdescription",link : "testlink",category : "testcategory")
entry.name.setDescriptor("name","testname")
entry.name.setDescriptor("html_tag","p")
entry.link.setDescriptor("name","inserat_link")
entry.link.setDescriptor("html_tag","a")
entry.link.setDescriptor("attrs","href")
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 10:10:21 +00:00
#entry.getEntryFromHtml()
2024-06-27 10:02:25 +00:00
test()