私はウェブサイトhttp://www.crowdrise.com/CDISkollで作業しています
私が作成した次の R コードを検討してください。
library("RCurl")
library("XML")
library("stringr")
user.address<-"http://www.crowdrise.com/CDISkoll"
user.url<-getURL(user.address)
html <- htmlTreeParse(user.url, useInternalNodes = TRUE)
if(!is.null(xpathSApply(html,
'//div[@class="grid1-4"]//p[@class="progressText"]',xmlValue))){
website.goal.percentage<-
do.call("paste",as.list(xpathSApply(html,
'//div[@class="grid1-4"]//p[@class="progressText"]',xmlValue)))
}
if(is.null(xpathSApply(html,
'//div[@class="grid1-4"]//p[@class="progressText"]',xmlValue))){
website.goal.percentage<-"Not Available"
}
上記のWebサイトには、 xpath に関する情報は含まれていません
//div[@class="grid1-4"]//p[@class="progressText"]
。したがって、私の変数website.goal.percentage
は文字列でなければなりません"Not Available"
。しかし、R でコードを実行すると、...website.goal.percentage
が返されます。character(0)
R"Not Available"
が変数website.goal.percentage
に格納されないのはなぜですか?どうすれば修正できますか?