[軟體熟悉度]:
小弟大概使用R一個月,之前有些寫過其他程式
[問題敘述]:
想利用R來抓網頁進行一些圖表分析
想利用xpathSApply來抓網頁內容,但讀不到網頁內容
[程式範例]:
getdoc <- function(line){
start <- regexpr('www', line)[1]
end <- regexpr('html', line)[1]
if(start != -1 & end != -1){
url <- substr(line, start, end+3)
html <- htmlParse(getURL(url), encoding='UTF-8', useInternalNodes = T)
doc <- xpathSApply(html, "//div[@id='main-content']", xmlValue)
name <- strsplit(url, '/')[[1]][4]
write(doc, gsub('html', 'txt', name))
}
}
sapply(data, getdoc)
有上網survey過也try過許多方法一直try不出來,因此想請問各位神人問題出在哪?
doc一直讀不出東西來
[關鍵字]:
xpathSApply