やりたいこと
- ご覧になりたい日付を選択
- ご覧になりたい日を選択
- ダウンロードされたファイルを特定のフォルダに保存
困っていること
- セレクトボックスから特定の月を選択
- ラジオボタンから特定の日を選択
- ダウンロードボタンを押してファイルを特定のフォルダに保存
と、つまりほぼ全ての処理がわからず困っています、、
※セレクトボックスとラジオボタンで選択する日は今日の日付です。
ファイルダウンロードまでできているコード(別ページ)
ruby
1require 'open-uri' 2require 'nokogiri' 3 4USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 5 + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36' 6url = 'https://www.boatrace.jp/owpc/pc/extra/data/download.html' 7doc = Nokogiri::HTML.parse(open(url, { 'User-Agent' => USER_AGENT })) 8 9def download_file(url, user_agent, referer) 10 Dir.mkdir('download') unless Dir.exist?('download') 11 file_name = DateTime.now.strftime("%Y%m%d%H%M%S") 12 open("download/#{file_name + File.extname(url)}", 'wb') do |out| 13 open(url, {'User-Agent' => user_agent, 'Referer' => referer}) do |data| 14 out.write(data.read) 15 end 16 end 17end 18 19doc.xpath('//ul[@class="data_list h-mt15"]/li[1]').each do |li_tag| 20 download_file('https://www.boatrace.jp' + li_tag.xpath('.//a/@href').text, USER_AGENT, url) 21end
https://teratail.com/questions/185589
こちらの質問で教えていただきました↑
取得したいファイルがあるサイト
http://www1.mbrace.or.jp/od2/K/dindex.html
ダウンロード手順
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/29 01:07