Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a browser in Ruby, with cookies?

Tags:

browser

ruby

It is possible to simulate a browser in Ruby? I know about OpenURI, but I want to simulate even the cookies behavior, etc.

like image 882
Mangano Avatar asked Oct 13 '10 22:10

Mangano


2 Answers

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.

like image 121
Matchu Avatar answered Nov 11 '22 07:11

Matchu


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
like image 29
Moriarty Avatar answered Nov 11 '22 06:11

Moriarty