I try to log on to a website using mechanize. I can submit my username
and password, but when I get redirected I have a problem.
I want to click on a link using following code:
link = page.links.href(/index.php?ahcd_obj=([a-z]|[0-9])*/)
page = agent.click(link)
(The RegExp is fine, I tested it manually)
It looks as if there is some hidden redirect or something like that,
because the result is always the same, that is I’m still on the same
page.
It looks as if there is some hidden redirect or something like that,
because the result is always the same, that is I’m still on the same
page.
The server can accomplish a redirect by sending back a page that is the
same as the original page, but that has a html tag. The
html tag can direct the browser go to a specified url in a given number
of seconds, which can be 0 seconds.
If that is the case, then you need to get the url specified in the
tag. You can examine the html of the page to see if it has a
html tag by looking at the output from:
page = agent.get(‘http://google.com/’)
puts page.body #which appears to be undocumented
Try that and post the first 20 lines or so of the output.
I cut of the end, because there are no meta-tags.
The site has some kind of script-protection: You have to click the right
of three links. There’s no methode to figure out which one is the right
link, so I login click a link, check the result and if I’m still on the
same page I logout and try again. So far I didn’t come around this
protection in Ruby, although this ‘algorithm’ works very well in the
browser.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.