title: How do I collect historical weather data from Wunderground using R function?
body: <p>Can anyone help me fixing this code?
  I used the script without issues last year, but now there is issues with the connection to the url.</p>
  
  <p>How do I fix it?</p>
  
  <p>What I want is to collect and arrange data from 2015-12-01 to 2016-04-15 from the weather station "EKAH" (Tirstrup, Aarhus Airport, Denmark).</p>
  
  <pre><code>    ############## 1) Run function --------------------
  
      wunder_station_daily &lt;- function(station, date)
      {
        base_url &lt;- 'https://www.wunderground.com/history/airport'
  
        # Example website: https://www.wunderground.com/history/airport/EKAH/2016/06/09/DailyHistory.html?&amp;MR=1
  
        # parse date
        m &lt;- as.integer(format(date, '%m'))
        d &lt;- as.integer(format(date, '%d'))
        y &lt;- format(date, '%Y')
  
        # compose final url
        final_url &lt;- paste(base_url,
                           '/', station,
                           '/', y,
                           '/', m, 
                           '/', d,
                           '/DailyHistory.html?&amp;MR=1', sep='')
  
        # reading in as raw lines from the web server
        # contains &lt;br&gt; tags on every other line
  
        #   u &lt;- url(final_url)
        #   the_data &lt;- readLines(u)
        #   close(u)
  
        the_data &lt;- getURL(final_url, ssl.verifypeer=0L, followlocation=1L)
  
        # only keep records with more than 5 rows of data
        if(length(the_data) &gt; 5 )
        {
          # remove the first and last lines
          the_data &lt;- the_data[-c(1, length(the_data))]
  
          # remove odd numbers starting from 3 --&gt; end
          the_data &lt;- the_data[-seq(3, length(the_data), by=2)]
  
          # extract header and cleanup
          the_header &lt;- the_data[1]
          the_header &lt;- make.names(strsplit(the_header, ',')[[1]])
  
          # convert to CSV, without header
          tC &lt;- textConnection(paste(the_data, collapse='\n'))
          the_data &lt;- read.csv(tC, as.is=TRUE, row.names=NULL, header=FALSE, skip=1)
          close(tC)
  
          # remove the last column, created by trailing comma
          the_data &lt;- the_data[, -ncol(the_data)]
  
          # assign column names
          names(the_data) &lt;- the_header
  
          # convert Time column into properly encoded date time
          the_data$Time &lt;- as.POSIXct(strptime(the_data$Time, format='%Y-%m-%d %H:%M:%S'))
  
          # remove UTC and software type columns
          the_data$DateUTC.br. &lt;- NULL
          the_data$SoftwareType &lt;- NULL
  
          # sort and fix rownames
          the_data &lt;- the_data[order(the_data$Time), ]
          row.names(the_data) &lt;- 1:nrow(the_data)
  
          # done
          return(the_data)
        }
      }
  
  
      ############## 2) Get data for a range of dates ------------------------------
  
  
      date.range &lt;- seq.Date(from=as.Date('2015-12-01'), to=as.Date('2015-12-04'), by='1 day')
      station &lt;- 'EKAH'
  
  
      # pre-allocate list
      l &lt;- vector(mode='list', length=length(date.range))
  
      # loop over dates, and fetch data
      for(i in seq_along(date.range))
      {
        print(paste0("Fetching data: ", date.range[i]))
        l[[i]] &lt;- wunder_station_daily('EKAH', date.range[i])
      }
  
      # stack elements of list into DF, filling missing columns with NA
      d &lt;- ldply(l)
  </code></pre>