- 環境
os:osx(最終的にはherokuで運用したいと考えていますが,開発環境はmacです)
ruby -v 2.2.4
- 質問内容
http://www.jukedeck.comに対して操作を行いmp3をダウンロードしたいのですが,そのためにはログインする必要があります.
しかし以下のようにtopにログイン用のformが見当たりませんでした.(モーダルウィンドウでログイン入力表示されるのでコードはあるがformに引っかからない)
ruby
1require 'mechanize' 2REQUEST_URL = "https://www.jukedeck.com" 3agent = Mechanize.new 4login = agent.get(REQUEST_URL)
ruby
1#実行結果(linkなどが多くてややこしいのでform以外は消しています) 2{forms 3 #<Mechanize::Form {name nil} {method "GET"} {action "https://www.jukedeck.com/"} {fields} {radiobuttons} {checkboxes} {file_uploads} {buttons [button:0x3fe049a2fdb4 type: name: value: ]}> 4 #<Mechanize::Form {name nil} {method "GET"} {action "https://www.jukedeck.com/"} {fields} {radiobuttons} {checkboxes} {file_uploads} {buttons [button:0x3fe049a91140 type: name: value: ]}> 5 #<Mechanize::Form {name nil} {method "GET"} {action "https://www.jukedeck.com/"} {fields} {radiobuttons} {checkboxes} {file_uploads} {buttons [button:0x3fe049a2ab34 type: name: value: ]}>
そこでpostでログイン出来ないか試した所,以下のコードであっさりログインはすることができました.
しかしget通信ではないのでhtmlがかえってきていないためにどの様にこの状態から操作すればよいかわからず詰まってしまいました.
このアクセストークンを旨く使えば良いのだろうとは思うのですがどうのように使えば良いのかさっぱりわかりません.
ruby
1require 'yaml' 2require 'fileutils' 3require 'mechanize' 4 5REQUEST_URL = "https://www.jukedeck.com/api/user/login" 6 7# yamlからmailとpassを取得 8nic = YAML.load_file("yml/user.yml") 9# 変数設定 10mail = nic["mail"] 11password = nic["pass"] 12agent = Mechanize.new 13login = agent.post(REQUEST_URL, { 14 #current_form:"login", 15 client_id: "P20ev5wveZ60kZ2J9KHkBis6r", 16 client_secret: "z5PjRToRbRuVkEJxpBTF5lRKsQDgRd4OY1r36zO5OuPGXmxQLc", 17 username:mail, 18 password:password, 19 })
実行結果 #<Mechanize::File:0x007f8582e48158 @body="{\"message\":\"User logged in\",\"accessToken\":\"hogehogehogehogehoge\"}", @code="200", @filename="login.html", @full_path=false, @response= {"content-type"=>"application/json; charset=utf-8", "date"=>"Sun, 13 Mar 2016 19:23:16 GMT", "etag"=>"W/\"hogehogehogehogehoge\"", "x-powered-by"=>"Express", "content-length"=>"89", "connection"=>"keep-alive"}, @uri=#<URI::HTTPS https://www.jukedeck.com/api/user/login>>
そこでここからどの様にすればmp3をdlできるのか,またはrubyのスクレイピングでMechanize以外で何かいいものがありましたらご教授ください.
よろしくお願い致します.
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/14 02:48
2016/03/14 05:19