2017-09-10 6 views
0

https://www.fantasysharks.com/apps/bert/forecasts/projections.phpから.csvファイルをダウンロードしようとしていますか? (静的なダウンロードリンクではない)入力設定に直接結び付けられ、Rにロードされます。ドロップボックスが入力されたら、ダウンロード.csvボタンをクリックする必要があります。私はこれを見つけましたUsing R to "click" a download file button on a webpage詳細については、POSTを使用してそれを行う方法をビットが、そのコードのいくつかの変更で動作するように取得することはできません。私はこのコードを試みた:R入力ボックスと "クリック"ボタンに接続された.csvファイルをダウンロード

library(httr) 
library(rvest) 
library(purrr) 
library(dplyr) 

POST("https://www.fantasysharks.com/apps/bert/forecasts/projections.php", 
body = list('League'=-1, 'Position'=1, 'scoring'=16, 'Segment'=596, 'uid'=4), 
encode = "form") -> res 
res 

が、エラーを考え出す:ここ

Response [https://www.fantasysharks.com/apps/bert/forecasts/projections.php] 
    Date: 2017-09-10 15:44 
    Status: 406 
    Content-Type: text/html; charset=iso-8859-1 
    Size: 286 B 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>406 Not Acceptable</title> 
</head><body> 
<h1>Not Acceptable</h1> 
<p>An appropriate representation of the requested resource /apps/bert/forecasts/projections.php could not be found on t... 
</body></html> 
+0

https://www.fantasysharks.com/terms-of-use/の「行動規範」をお読みください。 – hrbrmstr

答えて

1

はURLからCSVを取得するための簡単な方法です:

segment <- 596 
position <- 1 
scoring <- 16 
league <- -1 
uid <- 4 
csv_url <- sprintf("https://www.fantasysharks.com/apps/bert/forecasts/projections.php?csv=1&Segment=%s&Position=%s&scoring=%s&League=%s&uid=%s",segment,position,scoring,league,uid) 
res <- read.csv(url(csv_url)) 

まずパラメータを後でsprintfのダウンロードリンクを生成するために使用するさまざまな変数に設定します。次に、url関数を使用して、生成されたURLからファイルをダウンロードし、最後にファイルread.csvを読み取ります。

関連する問題