0

How do I download the 240km radar scans between 2022-07-31 01:00:00 (am) and 2022-07-31 03:00:00 (am) at five-minute intervals, inclusive of end points?

I've noted the pattern in the image url: https://www.nea.gov.sg/docs/default-source/rain-area-240km/dpsri_240km_2022073101000000dBR.dpsri.png

where the string of numbers would represent the date and time. Currently, I have:

library(rvest)
library(httr)
interval <- seq(0, 55, by = 5)
hour <- c("01", "02", "03")
for (h in hour) {
  for (i in interval) {
    url <- paste("https://www.nea.gov.sg/docs/default-source/rain-area-240km/dpsri_240km_20220731", h, i, ".dpsri.png", sep = "")
    imgurl <- read_html(url) %>%
      html_node(css = "img") %>%
      html_attr("src")
  }
}

However, when I run this code, I get: Error in open.connection(x, "rb") : HTTP error 404.

Where did I go wrong? Also, how would I download the images and save them into a zip file?

Thank you.

user19825372
  • 105
  • 4
  • 1
    You seem to be missing the `dpsri.png` (and perhaps more - I haven’t checked) at the end of the URL. – Limey Sep 20 '22 at 17:31
  • https://rdrr.io/r/utils/download.file.html & https://rdrr.io/r/utils/zip.html – margusl Sep 20 '22 at 19:24
  • @Limey Hi, what is dpsri.png and how do I use it? – user19825372 Sep 21 '22 at 05:03
  • As I said in my original comment, It’s the character string at the end of your URL. – Limey Sep 21 '22 at 05:15
  • @Limey Hi, upon your prompting, I have noticed that my url was incomplete. However, after fixing it (see edits in my qn), I was still faced with the same error – user19825372 Sep 21 '22 at 05:18
  • You index your loop by `i` yet reference `I` when constructing your URL. These are all issues that you should fix before posting your question. Those who might help you have no incentive to do so when questions are asked with such basic errors that could be identified with even the most basic and rudimentary debugging. Have you, for example, `print`ed your `url` to check it has the form you expect? I suspect not, and will be spending my time helping those who have invested more effort in their problem before posting their question. – Limey Sep 21 '22 at 05:56
  • I am not able to get access to the URL. Could you provide a URL that works? – Emmanuel Hamel Apr 17 '23 at 16:17

0 Answers0