为什么在运行这两个几乎相似的命令(字符串的开头除外)时得到不同的字符串输入
substr(getURL(paste("https://www.nordpoolgroup.com/4a9f52/globalassets/marketdata-excel-files/elspot-prices_2020_hourly_eur.xls")),10,90)
在这种情况下,我只有ces作为输出
substr(getURL(paste("https://www.nordpoolgroup.com/4a9f52/globalassets/marketdata-excel-files/elspot-prices_2020_hourly_eur.xls")),80,90)
答案 0 :(得分:0)
我无法复制您描述的结果。我确实得到了您期望的行为。我怀疑第二个http请求在某种程度上对您来说是错误的。您是否一再得到相同的结果?
substr(RCurl::getURL(paste("https://www.nordpoolgroup.com/4a9f52/globalassets/marketdata-excel-files/elspot-prices_2020_hourly_eur.xls")),10,90)
#> [1] "ad><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href=\"/4aa9e9"
substr(RCurl::getURL(paste("https://www.nordpoolgroup.com/4a9f52/globalassets/marketdata-excel-files/elspot-prices_2020_hourly_eur.xls")),80,90)
#> [1] "t Prices in"
为了不为每个操作下载数据,您可以先存储数据,如下所示:
a <- RCurl::getURL("https://www.nordpoolgroup.com/4a9f52/globalassets/marketdata-excel-files/elspot-prices_2020_hourly_eur.xls")
substr(a, 10, 90)
#> [1] "\n\t<body>\r\n\t\t<table>\r\n\t\t\t<thead>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td colspan=\"24\">Elspot Prices in"
substr(a, 80, 90)
#> [1] "t Prices in"
由reprex package(v0.3.0)于2020-11-02创建