News_0524 <- NULL
for (pageNo in 1:10) {
urls <- paste0("https://news.naver.com/main/list.naver?mode=LS2D&sid2=258&sid1=101&mid=shm&date=20220524&page=",pageNo)
html_source <- read_html(urls)
for (i in 1:20) {
T.selector <- paste0("#main_content > div.list_body.newsflash_body > ul.type06_headline > li:nth-child(",i,") > dl > dt:nth-child(2) > a")
title_nodes <- html_nodes(html_source,T.selector)
text_title <- html_text(title_nodes)
News_0524 <- c(News_0524,text_title)
}
}
df <- data.frame(News_0524)
df[,1]<- gsub("\t","",df[,1])
df[,1]<- gsub("\n","",df[,1])
df[,1]<- gsub(" ","",df[,1])
#전처리할때 [,1] 데이터 프레임으로 전처리함 -> 열 행 이니 , 행의 불필요한 부분을 모두 없앤다
df