Using a Ruby script to login to a website via https

后端 未结 3 1926
醉梦人生
醉梦人生 2021-01-30 09:28

Alright, so here\'s the dealio: I\'m working on a Ruby app that\'ll take data from a website, and aggregate that data into an XML file.

The website I need to take data f

相关标签:
3条回答
  • 2021-01-30 10:01

    You can try use wget to fetch the page. You can analyse login process with this app www.portswigger.net/proxy/.

    0 讨论(0)
  • 2021-01-30 10:04

    For what it's worth, you could check out Webrat. It is meant to be used a tool for automated acceptance tests, but I think you could use it to simulate filling out the login fields, then click through links by their names, and grab the needed HTML as a string. Haven't tried doing anything like it, tho.

    0 讨论(0)
  • 2021-01-30 10:13

    Mechanize

    Mechanize is ruby library which imititates the behaviour of a web browser. You can click links, fill out forms und submit them. It even has a history and remebers cookies. It seems your problem could be easily solved with the help of mechanize.

    The following example is taken from http://docs.seattlerb.org/mechanize/EXAMPLES_rdoc.html:

    require 'rubygems'
    require 'mechanize'
    
    a = Mechanize.new
    a.get('http://rubyforge.org/') do |page|
      # Click the login link
      login_page = a.click(page.link_with(:text => /Log In/))
    
      # Submit the login form
      my_page = login_page.form_with(:action => '/account/login.php') do |f|
        f.form_loginname  = ARGV[0]
        f.form_pw         = ARGV[1]
      end.click_button
    
      my_page.links.each do |link|
        text = link.text.strip
        next unless text.length > 0
        puts text
      end
    end
    
    0 讨论(0)
提交回复
热议问题