-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.txt
67 lines (50 loc) · 2.32 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
The main purpose of this project is to take an HTML document and make it
lisp-readable. This allows you to perform all sorts of algorithms on it. If you
want to find all the <span>-elements in the document, you can do just that. If
you wanted to get the average of all element occurences, you could probably do
that as well.
The only remaining major weakness (I have tested for) is that JSON data in an
attribute string can cause some issues.
Example usage:
`curl https://en.wikipedia.org/wiki/Main_Page -o main.html`, which can then be
opened in Spyglass via `(parse "main.html")`. For an example see `example.lisp`.
Instead of parsing the same file over and over again, you can also save the
result of a call to parse in an external file using `parse-into-file`.
File structure:
+----------------+-------------------------------------------------------------+
| spyglass.lisp | contains the main code for parsing and analysing the nodes |
| | of a supplied html document. The exported functions can be |
| | used in other lisp files. |
+----------------+-------------------------------------------------------------+
| example.lisp | an example use case of the spyglass library. |
+----------------+-------------------------------------------------------------+
To use this project, the only thing you need is a working Lisp compiler. It
should be enough to simply load the project file `spyglass.lisp`. After that,
you should be able to use all of the exported functions.
Exported Symbols:
make-node:
`make-node &key name attrs text children`
creates a new instance of a struct node
node-p:
`node-p instance`
returns true when instance is of type node
node-name:
`node-name instance`
returns the name of a node
node-attrs:
`node-attrs instance`
returns the list of attributes of a node, attributes are saved in the following
format: ((:KEY . "value") ...)
node-children:
`node-children instance`
returns the list of children of a node
find-all-nodes:
`collect-nodes node predicate`
returns all child nodes of root and root itself for which the predicate function
returns true
find-node:
`find-node node predicate`
returns the first node which satisfies the predicate
node-has:
`node-has node attribute value`
returns whether or not the attribute of a node has a certain value