Dongkun Lee Dongkun Lee -4 years ago 70
Ruby Question

Ruby : Mechanize cannot find any content from the site what i want to check

i want use auto login for specific web site

so i decided to use "Mechanize"

In example, like google.com, It works!

require 'rubygems'
require 'mechanize'

a = Mechanize.new { |agent|
agent.user_agent_alias ="Windows Chrome"
}

page = a.get('http://www.google.com/')

puts page.search("div")


but when set url to http://lms.kyonggi.ac.kr/

I cannot find any content

I tried several functions like


  • page.links

  • page.search(:id=>"wrap_login")

  • page.search(".loginfrom")
    ....



But I cannot catch any content in this site

How can I get login contents from the site http://lms.kyonggi.ac.kr/

Answer Source

That page has two iframes so you need to click the iframe first, then only you can find the elements.

require 'rubygems'
require 'mechanize'

a = Mechanize.new
page = a.get('http://lms.kyonggi.ac.kr/')
p = page.frames[1].click
puts p.search("div")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download