抓取数据时包括两个倍数

时间:2020-01-23 14:11:38

标签: r web-scraping

希望从

抓取天气数据

https://www.wetterzentrale.de/weatherdata.php?station=260&jaar=2019&maand=1&dag=1

从2019-01-01到今天,但我不知道如何编写更改jaar = 2019(即year = 2019),maand = 1(即month = 1)和dag = 1的代码(即天= 1)到所需的天。

我尝试以如下方式使用lapply:

    years <- c("2019", "2020")
    urls <- rbindlist(lapply(years, function(x) {
       url <- paste(https://www.wetterzentrale.de/weatherdata.php?station=260&jaar=2019&maand=1&dag=1, sep = "")
       data.frame(url)
    } ))

因此,这仅给出了2019年和2020年的网址。有没有办法包含月份和日期?

1 个答案:

答案 0 :(得分:1)

library(lubridate)

allYourDates <- seq(ymd(20190101), Sys.Date(), by = "days")
urls <- paste("https://www.wetterzentrale.de/weatherdata.php?station=260&jaar=", year(allYourDates)
              , "&maand=", month(allYourDates)
              , "&dag=", day(allYourDates)
              , sep = "")
相关问题