特定のWebサイトからレポートを取得する機能が必要です。content-disposition:filename=report.csv
以下のメソッドは、必要なすべてのことを実行します。唯一のキャッチは、ページが投稿されたとき(ページがそれ自体に投稿されたとき)に応答ヘッダーに「」が含まれるレポート「report.csv」が返されることです。
def download_report
page = @mechanize.click(@mechanize.current_page().link_with(:text => /Reporting/))
page.form.field_with(:name => "rep").option_with(:value => "adperf").click
page.form_with(:name => "get-report").field_with(:id => "sasReportingQuery.dateRange").option_with(:value => "Custom").click
start_date = DateTime.parse(@start_date)
end_date = DateTime.parse(@end_date)
page.form_with(:name => "get-report").field_with(:name => "sd_display").value = start_date.strftime("%m/%d/%Y")
page.form_with(:name => "get-report").field_with(:name => "ed_display").value = end_date.strftime("%m/%d/%Y")
page.form_with(:name => "get-report").submit
end
私の知る限り、Mechanizeはファイルを取得できる場所にキャプチャしていません。Mechanizeにこのファイルをキャプチャしてダウンロードさせる方法はありますか?
@mechanize.current_page()
ファイルが含まれておら@mechanize.history()
ず、ファイルのURLがMechanizeに提示されたことを示していません。