require "lwqzx/version" require 'nokogiri' module Lwqzx def self.auth(login,passwd) lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/active_app/login1.php" user = "login_user_m_=#{login}" psd = "login_password=#{passwd}" res = %x[curl #{lurl} -s -c /tmp/cookies -d #{user} -d #{psd} ] infos = %x[curl -s -b /tmp/cookies #{lurl}] content=infos.encode("UTF-8","GB2312") doc = Nokogiri::HTML(content) uname = doc.css("span.tt1 a:nth-child(1)").text return {} if uname == "" groups = doc.css("span.tt1 a:nth-child(5)")[0]["title"] %x[rm /tmp/cookies] groups=groups.gsub("[","").gsub("]","").split("@").compact.reject(&:empty?) return {login: login, name: uname, groups: groups} end end Lwqzx.auth("dsfas","dsfasd")