# \[✓\] Import data from a URL (COVID-19)

**URL:** <https://community.wolfram.com/t/import-data-from-a-url-covid-19/15666>\
**Category:** Questions\
**Tags:** data-science, import-and-export\
**Created:** [April 4, 2020, 3:25pm UTC](https://community.wolfram.com/t/import-data-from-a-url-covid-19/15666 "2020-04-04T15:25:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillermo](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/guillermo/32/16702_2.png) [@guillermo](https://community.wolfram.com/u/guillermo)\
**Post date:** [April 4, 2020, 3:25pm UTC](https://community.wolfram.com/t/import-data-from-a-url-covid-19/15666/1 "2020-04-04T15:25:30Z")

</div>

How the below file can be imported

```
Import["https://analisis.datosabiertos.jcyl.es/explore/dataset//situacion-de-hospitalizados-por-coronavirus-en-castilla-y-leon//download/?format=xls&timezone=Europe/Madrid&lang=es&use_labels_for_\header=true"]

```

You can copy and paste the URL address in a web browser and the file is downloaded

Thank you

Guillermo

---

<div class="post-metadata">

**Author:** ![jasonb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jasonb/32/20741_2.png) [@jasonb](https://community.wolfram.com/u/jasonb)\
**Post date:** [April 4, 2020, 3:57pm UTC](https://community.wolfram.com/t/import-data-from-a-url-covid-19/15666/2 "2020-04-04T15:57:59Z")

</div>

If I download the file, I get errors trying to import it. So the problem is independent of the URL.

I was able to open it in LibreOffice and then save again as an XLS file, which I could import to mathematica.

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [April 4, 2020, 11:41pm UTC](https://community.wolfram.com/t/import-data-from-a-url-covid-19/15666/3 "2020-04-04T23:41:51Z")

</div>

Hello Guillermo,

The data is in XML format (representing a spreadsheet) but `Import` doesn’t know that. If you provide “XML” as the second argument to `Import`, it works fine. However dealing with spreadsheet XML is not fun. As HTML is kind of a derivative of XML I tried with `Import["the url","HTML"]` and it works! So you just need to do some string processing after that to get the data in a useful way.

The first step is importing the data as a string:

```
s = Import[
        "https://analisis.datosabiertos.jcyl.es/explore/dataset//situacion-de-hospitalizados-por-coronavirus-en-castilla-y-leon//download/?format=xls&timezone=Europe/Madrid&lang=es&use_labels_for_\\header=true",
        "HTML"
    ]

(* fecha hospital provincia hospitalizados_planta hospitalizados_uci altas fallecimientos codigo_ine 2020-03-18 Complejo Asistencial de Ávila Ávila 24 1 1 1 5019 2020-03-18 Hospital de El Bierzo León 5 1 0 0 24089 (...etc...) 2020-04-04 Hospital Universitario Río Hortega Valladolid 157 51 244 58 47186 *)

```

Then we separate the header from the data, convert the date, split and partition:

```
{header, data} = StringSplit[s, d:DatePattern[{"Year","Month","Day"}] :> DateObject[d]] //
        {First /* StringSplit, Rest /* (Partition[#, 2] &) } //
    Through

```

and finally we can use a carefully crafted string expression to separate the strings into fields so that we can convert to a dataset:

```
ds = 
    Map[
        StringCases[
            #[[2]],
            f1:Except[DigitCharacter].. ~~" "~~
            f2:WordCharacter.. ~~" "~~
            f3:NumberString ~~" "~~
            f4:NumberString ~~" "~~
            f5:NumberString ~~" "~~
            f6:NumberString ~~" "~~
            f7:NumberString :> AssociationThread[header->{#[[1]],f1,f2,f3,f4,f5,f6,f7}]
        ] &,
        data] //
      Flatten //
    Dataset

```

 ![dataset.png](https://global.discourse-cdn.com/wolfram/original/1X/968a9f96b880b462426e1833ece49b4b89f94ccc.png)
