This repository has been archived by the owner on Jun 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_options.R
105 lines (80 loc) · 2.91 KB
/
get_options.R
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#' get search options for president
#'
#' \code{\link{search_speech}} 함수에서 사용할 president 조건을 출력합니다.
#' 대통령에 대한 값들을 확인할 수 있습니다.
#' 인터넷을 사용하는 기능입니다.
#'
#' @return character vector로 역대 대통령:president을 확인합니다.
#'
#' @export
#' @importFrom rvest html_nodes
#' @importFrom rvest html_text
#' @importFrom rvest html_attr
#' @importFrom xml2 read_html
get_president <- function(){
tar <- "http://www.pa.go.kr/research/contents/speech/index.jsp"
hobj <- xml2::read_html(tar)
category <- rvest::html_nodes(hobj, "ul.iList li label")
category <- rvest::html_attr(category, "for")
label <- rvest::html_nodes(hobj, "ul.iList li label")
label <- rvest::html_text(label)
res <- data.frame(category, label, stringsAsFactors = F)
res <- res[-grep("[a-z]0", res$category),]
res <- res[grep("damPst", res$category),]
res <- res$label
res <- sapply(strsplit(res, " "), function(x) x[1])
return(res)
}
#' get search options for field
#'
#' \code{\link{search_speech}} 함수에서 사용할 field 조건을 출력합니다.
#' 분야에 대한 값들을 확인할 수 있습니다.
#' 인터넷을 사용하는 기능입니다.
#'
#' @return character vector로 분야:field를 확인합니다.
#'
#' @export
#' @importFrom rvest html_nodes
#' @importFrom rvest html_text
#' @importFrom rvest html_attr
#' @importFrom xml2 read_html
get_field <- function(){
tar <- "http://www.pa.go.kr/research/contents/speech/index.jsp"
hobj <- xml2::read_html(tar)
category <- rvest::html_nodes(hobj, "ul.iList li label")
category <- rvest::html_attr(category, "for")
label <- rvest::html_nodes(hobj, "ul.iList li label")
label <- rvest::html_text(label)
res <- data.frame(category, label, stringsAsFactors = F)
res <- res[-grep("[a-z]0", res$category),]
res <- res[grep("Field", res$category),]
res <- res$label
return(res)
}
#' get search options for event
#'
#' \code{\link{search_speech}} 함수에서 사용할 event 조건을 출력합니다.
#' 유형에 대한 값들을 확인할 수 있습니다.
#' 인터넷을 사용하는 기능입니다.
#'
#' @return character vector로 유형:event을 확인합니다.
#'
#' @export
#' @importFrom rvest html_nodes
#' @importFrom rvest html_text
#' @importFrom rvest html_attr
#' @importFrom xml2 read_html
#' @importFrom tibble tibble
get_event <- function(){
tar <- "http://www.pa.go.kr/research/contents/speech/index.jsp"
hobj <- xml2::read_html(tar)
category <- rvest::html_nodes(hobj, "ul.iList li label")
category <- rvest::html_attr(category, "for")
label <- rvest::html_nodes(hobj, "ul.iList li label")
label <- rvest::html_text(label)
res <- data.frame(category, label, stringsAsFactors = F)
res <- res[-grep("[a-z]0", res$category),]
res <- res[grep("Event", res$category),]
res <- res$label
return(res)
}