Created
November 16, 2011 08:24
-
-
Save dongyuwei/1369574 to your computer and use it in GitHub Desktop.
自动登陆erp,搜索公司同事通讯录信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
#author [email protected] | |
%w(rubygems mechanize iconv).each{|lib| require lib} | |
def auto_search(name,password,keyword) | |
m = Mechanize.new | |
m.get('http://cas.erp.sina.com.cn/cas/login?ext=&service=http://searchemp.erp.sina.com.cn/login02.asp') do |page| | |
my_page = page.form_with(:name => 'login_form') do |f| | |
f.username = name | |
f.password = password | |
end.submit | |
search_link = my_page.body.split("window.location.href=")[1].split('"')[1].sub(";","") | |
puts search_link | |
m.get(search_link) do|page| | |
puts '--------\n' | |
link = page.body.split("top.location.href=")[1].split('"')[1] | |
puts link | |
m.get("http://searchemp.erp.sina.com.cn/fastsearch.asp?queryType=name&nameInput=#{keyword}") do|page| | |
puts Iconv.iconv("UTF-8//IGNORE","GB2312//IGNORE",page.body) | |
end | |
end | |
end | |
end | |
if __FILE__ == $0 | |
auto_search('yuwei','my password','dyw') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment