Search code examples
rhttr

How to download a file from a link that is a forced download


Using R, I want to grab the .csv from this site: https://vacationwithoutacar.com/gvrat-tracking/ but there is no link associated with the download it just pops up automatically. Usually, I would use httr to download but when I right-click the the link it doesn't give me the option to copy a URL. There's not much of a reproducible example because, well, I can't even get the file downloaded.

GET("https://vacationwithoutacar.com/gvrat-tracking/",
    write_disk("gvrat.txt", 
               overwrite = TRUE)
    )

Solution

  • This seems to work...

    I opened the URL in chrome, hit F12, clicked network, trash can to clear, reload page. Then looked for some request to download the data. I saw the URL below returned JSON.

    library(jsonlite)
    df <- fromJSON("https://vacationwithoutacar.com/wp-admin/admin-ajax.php?action=wp_ajax_ninja_tables_public_action&table_id=2596&target_action=get-all-data&default_sorting=old_first")
    > head(df)
    pos   bib participantsname event  home g   a miles    km yourapproximatelocation   comp projfin 51 52 53 54
    1   1 17395  Gingerbread Man GVRAT US-TN M 145 275.6 443.5           Cowley Hollow 43.50%     tbd 83 43 49 52
    2   2  1074    Terri Biloski GVRAT CA-ON F  44 274.6 442.0           Cowley Hollow 43.30%     tbd 63 59 52 52
    3   3  1429     Dave Proctor GVRAT CA-AB M  39 255.3 410.8           Cowley Hollow 40.30%     tbd 62 62  5 62
    4   4   743       John Sharp GVRAT US-TX M  42 235.0 378.2             Reed Hollow 37.10%     tbd 34 41 46 54
    5   5   386       Roc Powell GVRAT US-OH M  60 226.0 363.7          Britton Hollow 35.60%     tbd 35 75 63 43
    6   6   322  Rob Donkersloot GVRAT    AU M  60 190.7 306.9          past Deerfield 30.10%     tbd 42 42 43 32
      55 56 57 58 59 51_1
    1 48                 
    2 48                 
    3 63                 
    4 60                 
    5 10                 
    6 32