R XML Parse for a web address

前端 未结 2 2086
清酒与你
清酒与你 2021-01-06 17:29

I am trying to download weather data, similar to the question asked here: How to parse XML to R data frame but when I run the first line in the example, I get \"Error: 1: fa

2条回答
  •  悲&欢浪女
    2021-01-06 17:33

    I downloaded this url to a text file. After that, I get the content of the file and parse it to XML data. Here is my code:

    rm(list=ls())
    require(XML)
    require(xml2)
    require(httr)
    
    url <- "http://forecast.weather.gov/MapClick.php?lat=29.803&lon=-82.411&FcstType=digitalDWML"
    
    download.file(url=url,"url.txt" )
    xmlParse(url)
    data <- xmlParse("url.txt")
    
    xml_data <- xmlToList(data)
    
    location <- as.list(xml_data[["data"]][["location"]][["point"]])
    
    start_time <- unlist(xml_data[["data"]][["time-layout"]][
        names(xml_data[["data"]][["time-layout"]]) == "start-valid-time"])
    

提交回复
热议问题