开发者

Mechanize on HTTPS site

开发者 https://www.devze.com 2022-12-16 01:48 出处:网络
Has anyone used the Mechanize gem on a site that required SSL? When I try to access such a 开发者_JAVA技巧website Mechanize tries to use standard HTTP which results in endless redirections between ht

Has anyone used the Mechanize gem on a site that required SSL?

When I try to access such a 开发者_JAVA技巧website Mechanize tries to use standard HTTP which results in endless redirections between http:// and https://.


Mechanize works just fine with HTTPS. Try setting

agent.log = Logger.new(STDOUT)

to see what's going on between Mechanize and the server. If you are still having trouble, post a sample of the code and somebody will help.


I just gave Mechanize a try with my company's web site. The home page is HTTP, but it contains a link, "customer login," which sends the browser to an HTTPS page. It worked fine. The code is:

#!/usr/bin/ruby1.8

require 'rubygems'
require 'mechanize'

agent = WWW::Mechanize.new
page = agent.get("http://www.not_the_real_url.com")
link = page.link_with(:text=>"CUSTOMER LOGIN")
page = link.click
form = page.forms.first
form['user_login'] = 'not my real login name'
form['user_password'] = 'not my real password'
page = form.submit
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号