2016-06-21 45 views

回答

2

如果您只需要PE比你可以用這個

library(XML) 
library(stringr) 
url<-htmlParse("http://www.multpl.com/") 
PE<-xpathSApply(url,"//div[@id='current']",xmlValue) 
str<-str_replace_all(PE," ","") 
str<-str_replace_all(str,"\n","") 
begin<-str_locate(str,":")[[1]] 
end<-str_locate(str,"\\+")[[1]] 
PE_ratio<-as.numeric(str_sub(str,begin+1,end-1)) 
PE_ratio 
+0

好極了,是的,這正是我一直在尋找。 – Oposum