Init
This commit is contained in:
commit
1288c0a215
31
main.nim
Normal file
31
main.nim
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import std/httpclient
|
||||||
|
import std/htmlparser
|
||||||
|
import std/xmltree
|
||||||
|
import std/strtabs
|
||||||
|
import std/os
|
||||||
|
|
||||||
|
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)
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
17
scrap.nim
Normal file
17
scrap.nim
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
type
|
||||||
|
Entry* = object
|
||||||
|
name*, tag*, description*, link*, category* : string
|
||||||
|
|
||||||
|
proc getEntryFromHtml(entry : Entry) =
|
||||||
|
echo(entry.description)
|
||||||
|
|
||||||
|
proc test() =
|
||||||
|
var entry: Entry
|
||||||
|
entry = Entry(name : "testname",description : "testdescription",link : "testlink",category : "testcategory")
|
||||||
|
entry.getEntryFromHtml()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#echo "run test"
|
||||||
|
|
||||||
|
test()
|
Loading…
Reference in New Issue
Block a user