rm(list=ls(all.names=TRUE))
library(XML)
library(RCurl)
library(httr)
urlPath <- "https://www.ptt.cc/bbs/movie/index.html"
temp <- getURL(urlPath, encoding = "big5")
xmldoc <- htmlParse(temp)
title <- xpathSApply(xmldoc, "//div[@class=\"title\"]", xmlValue)
title <- gsub("\n", "", title)
title <- gsub("\t", "", title)
emptyId <- which(title == "(本文已被刪除) [brukling]")
title <- title[-emptyId]
author <- xpathSApply(xmldoc, "//div[@class='author']", xmlValue)
empty <- author == "-"
author <- author[!empty]
date <- xpathSApply(xmldoc, "//div[@class='date']", xmlValue)
date <- date[-emptyId]
response<- xpathSApply(xmldoc, "//div[@class='nrec']", xmlValue)
response<- response[-emptyId]
path <- xpathSApply(xmldoc, "//div[@class='title']/a//@href")
alldata <- data.frame(title, author, path, date, response)
write.table(alldata, "pttmovie.csv")
library(knitr)
## Warning: package 'knitr' was built under R version 3.3.3
data = read.table("pttmovie.csv")
kable(data)
[問微雷]明天我要和昨天的妳約會時間 |
WERGGC |
/bbs/movie/M.1490118137.A.736.html |
3/22 |
1 |
[討論]金剛:骷髏島的片尾彩蛋(含雷) |
gung76086 |
/bbs/movie/M.1490118204.A.E7F.html |
3/22 |
8 |
[討論] 致敬童年 - 金剛戰士 |
yorkbuster |
/bbs/movie/M.1490133272.A.883.html |
3/22 |
55 |
[問片] 一部反好萊屋經典元素的電影 |
agl0726 |
/bbs/movie/M.1490138063.A.875.html |
3/22 |
4 |
[好雷]【我和我的冠軍女兒】別忘了翅膀是拿來飛 |
ariel119 |
/bbs/movie/M.1490139880.A.916.html |
3/22 |
6 |
[討論] 美女與野獸 的補完計劃(? |
kyodaisuki |
/bbs/movie/M.1490143095.A.924.html |
3/22 |
7 |
[好雷] 星際過客 |
GiPla |
/bbs/movie/M.1490147457.A.6EA.html |
3/22 |
3 |
[片單] 聲勢與主角不相上下的配角 |
s12457845 |
/bbs/movie/M.1490147592.A.B00.html |
3/22 |
51 |
[無雷] 目擊者 Who killed Cock Robin |
kenji1101 |
/bbs/movie/M.1490147683.A.3BB.html |
3/22 |
1 |
[問片] 毒販 似乎港片 非門徒(已解決 |
mailman |
/bbs/movie/M.1490150343.A.6BB.html |
3/22 |
4 |
[好雷] 最後12天的生命之旅 |
zzzzzken |
/bbs/movie/M.1490151219.A.2D0.html |
3/22 |
|
[好無雷] 攻敵必救 Miss Sloane |
biboga |
/bbs/movie/M.1490151896.A.89F.html |
3/22 |
2 |
Re: [討論] 人生中覺得最好看的三部電影 |
james441 |
/bbs/movie/M.1490152054.A.539.html |
3/22 |
2 |
[新聞] 最強綠葉回歸「蟻人2」恐落空?竟自曝「 |
pneumo |
/bbs/movie/M.1490153925.A.0ED.html |
3/22 |
7 |
[公告]《各式疑難雜症FAQ》 |
yunyun85106 |
/bbs/movie/M.1397887191.A.BD0.html |
4/19 |
23 |
[公告] 板規!必看!|好文推薦‧惡文檢舉 |
ericf129 |
/bbs/movie/M.1468848054.A.77E.html |
7/18 |
爆 |