我关注Mechanize guide,但无法提交表单。 我的想法是通过Telegram bot通过查询获取发票。由于有一个验证码,我以为我可以通过Mechanize读取验证码图像src,通过Telegram发送该图像。然后,我会输入我可以在图像上看到的数字并发回到Mechanize以填充第二个输入字段。 代码:
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Windows Chrome'
page = agent.get('https://ercdmd.ru/?gpay')
form = page.forms.first
form.gpay_abon = '04-0000000000'
captcha_url = "https://ercdmd.ru/captcha.php?time=#{Time.now.to_i}000"
p captcha_url
captcha = gets.chomp
form.captcha = captcha
page = agent.submit(form, form.buttons.first)
输出:
/home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:177:in `block (2 levels) in initialize': Mechanize::UnsupportedSchemeError (Mechanize::UnsupportedSchemeError) from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:645:in `call' from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:645:in `resolve' from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:234:in `fetch' from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize.rb:1323:in `post_form' from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/mechanize-2.7.5/lib/mechanize.rb:584:in `submit' from parser.rb:26:in `<main>'