首页 > 解决方案 > 如何从强制下载的链接下载文件

问题描述

使用 R,我想从该站点获取 .csv:https ://vacationwithoutacar.com/gvrat-tracking/但没有与下载相关的链接,它只是自动弹出。通常,我会使用httr下载,但是当我右键单击该链接时,它不会给我复制 URL 的选项。没有太多可重复的示例,因为我什至无法下载文件。

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

标签: rhttr

解决方案


这似乎工作......

我在 chrome 中打开 URL,按 F12,点击网络,垃圾箱清除,重新加载页面。然后寻找一些下载数据的请求。我看到下面的 URL 返回了 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        

推荐阅读