如何从强制下载的链接中下载文件?

问题描述 投票:3回答:1

使用R,我想从这个网站抓取.csv。https:/vacationwithoutacar.comgvrat-tracking. 但没有与下载相关的链接,只是自动弹出。通常情况下,我会使用 httr 下载,但当我右键点击链接时,它没有给我复制URL的选项。没有什么可复制的例子,因为,我甚至无法下载文件。

GET("https://vacationwithoutacar.com/gvrat-tracking/",
    write_disk("gvrat.txt", 
               overwrite = TRUE)
    )
r httr
1个回答
3
投票

这似乎是工作...

我在chrome中打开网址,按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        
© www.soinside.com 2019 - 2024. All rights reserved.