So, I'm trying to automate the downloading of images from a website for which you have to login. The login form is on every page (in the browser you click "login" and a javascript slidedown occurs revealing the form). I login using the below code and when I get to agent.get( "http://cdn.com/some_image.jpg" ), a 403 error is thrown. This doesn't happen when I login into the browser and visit "http://cdn.com/some_image.jpg", so what is going on and how can I get around it?
path = "http://www.example.com/some_path"
agent = Mechanize.new
page = agent.get(path) do |page|
form = page.form_with(action: "http://www.example.com/authorize")
username_field = form.field_with(name: "username")
username_field.value = "some_user"
password_field = form.field_with(name: "password")
password_field.value = "password"
form.submit
end
agent.get( "http://cdn.com/some_image.jpg" ).save "some_image.jpg" unless File.exist?("some_image.jpg")