[問題] xpathSApply 問題

作者: dan40418 (成登)   2014-11-09 20:35:47
[軟體熟悉度]:
小弟大概使用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
作者: Wush978 (拒看低質媒體)   2014-11-09 20:42:00
有reproducible example嗎? 會讓想幫忙的版友比較容易測
作者: psinqoo (零度空間)   2014-11-09 22:31:00
RCURL XML
作者: john5601 (HTC粉)   2014-11-20 02:13:00
https://imgur.com/XPVGJaL 試試 我剛剛試了可以抓到

Links booklink

Contact Us: admin [ a t ] ucptt.com