无法从R中的XML库重现第一个示例

时间:2014-09-22 14:23:54

标签: xml r

当我跑步时:

example(readHTMLTable)

我收到以下错误:

Error: failed to load HTTP resource

已安装并运行库XML。这是我的会话信息:

> sessionInfo()
 R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reshape2_1.4  ggplot2_1.0.0 XML_3.98-1.1  dplyr_0.2    

loaded via a namespace (and not attached):
 [1] assertthat_0.1   colorspace_1.2-4 digest_0.6.4     grid_3.1.1       gtable_0.1.2    
 [6] magrittr_1.0.1   MASS_7.3-33      munsell_0.4.2    parallel_3.1.1   plyr_1.8.1      
[11] proto_0.3-10     Rcpp_0.11.2      scales_0.2.4     stringr_0.6.2    tools_3.1.1    

我是否需要安装其他库?

1 个答案:

答案 0 :(得分:0)

发生错误时,请加载httr包并调用它。以下是我自己的工作中的示例,其中第一个XML调用返回错误但httr调用没有:

require(httr)

doc <- htmlTreeParse('http://www.lewisthomason.com/locations/', useInternal = TRUE)
doc <- content(GET('http://www.lewisthomason.com/locations/'))