看板 R_Language 關於我們 聯絡資訊
[軟體熟悉度]: 小弟大概使用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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.201.208 ※ 文章網址: http://www.ptt.cc/bbs/R_Language/M.1415536549.A.7C0.html
Wush978: 有reproducible example嗎? 會讓想幫忙的版友比較容易測 11/09 20:42
psinqoo: RCURL XML 11/09 22:31
john5601: https://imgur.com/XPVGJaL 試試 我剛剛試了可以抓到 11/20 02:13