Simulate a browser in Ruby, with cookies?
It is possible开发者_如何学运维 to simulate a browser in Ruby? I know about OpenURI, but I want to simulate even the cookies behavior, etc.
Mechanize is the way to go for basic things like simplifying interaction, holding onto cookies, etc.
For full browser simulation, though, including fancy things like Javascript, we're more limited. A tool like Watir, however, can actually open up the browser and run it as your code dictates, which can sometimes be the only option if interacting with complex Javascript applications is a requirement.
If you don't need to execute javascript you could also try: Curb
Curl::Easy.perform(uri) do |curl|
curl.enable_cookies = true
curl.follow_location = true
end
精彩评论