cool_wiki

웹 크롤러 제작기 00 본문

Development/Triks

웹 크롤러 제작기 00

0cool 2019. 3. 4. 00:02

Go를 사용해서 간단한 웹 크롤러를 만들고 있다.



golang.org/x/net/html/atom 라이브러리를 보고있는데, html 요소를 node라는 자료구조를 기반으로 관리하고 있었다.


보아하하니 트리 기반으로 각 태그를 관리하고, 재귀적으로 이를 탐색하며 사용하는 방식인데..


(해당부분 코드첨부)


 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
package html

import (
	"golang.org/x/net/html/atom"
)

// A NodeType is the type of a Node.
type NodeType uint32

const (
	ErrorNode NodeType = iota
	TextNode
	DocumentNode
	ElementNode
	CommentNode
	DoctypeNode
	scopeMarkerNode
)

var scopeMarker = Node{Type: scopeMarkerNode}


type Node struct {
	Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

	Type      NodeType
	DataAtom  atom.Atom
	Data      string
	Namespace string
	Attr      []Attribute
}



문제는 너무 오랜만에 트리를 봐서 도통 감이 잡히지 않는다..


트리와 관련된 정보를 정리해서 아마 포스팅을 한번 해야하지 않을까 싶다..



(많이 사용하는 자료구조들을 golang으로 컨버팅해서 관리할까나...)






'Development > Triks' 카테고리의 다른 글

go언어 테이블 기반 테스트 작성하기  (0) 2018.12.15
Comments