require 'rubygems'
require 'whois'
c = Whois::Client.new
r = c.lookup("seogroup.com")
puts r.admin_contacts
produces this:
#<struct Whois::Record::Contact id=nil, type=2, name="Marvin Russell", organization="SEO Group, LLC", address="222 W Ontario", city="Chicago", zip="60654", state="Illinois", country="United States", country_code=nil, phone="847-452-9902", fax=nil, email="marvin@seogroup.com", url=nil, created_on=nil, updated_on=nil>
我如何获得这些属性,如“州”,“电子邮件”和“姓名”等。
答案 0 :(得分:1)
当我运行你的代码时,我得到了一个数组:
2.1.2 :013 > r.admin_contacts
=> [#<struct Whois::Record::Contact id=nil, type=2, name="Marvin Russell", organization="SEO Group, LLC", address="222 W Ontario", city="Chicago", zip="60654", state="Illinois", country="United States", country_code=nil, phone="847-452-9902", fax=nil, email="marvin@seogroup.com", url=nil, created_on=nil, updated_on=nil>]
然后反省一点我看到了:
2.1.2 :014 > r.admin_contacts.class
=> Array
2.1.2 :015 > r.admin_contacts.length
=> 1
2.1.2 :016 > r.admin_contacts[0].class
=> Whois::Record::Contact
然后我看了一下可用的方法:
2.1.2 :017 > r.admin_contacts[0].methods
=> [:id, :id=, :type, :type=, :name...
然后拿起名字和电子邮件:
2.1.2 :018 > r.admin_contacts[0][:name]
=> "Marvin Russell"
2.1.2 :019 > r.admin_contacts[0][:email]
=> "marvin@seogroup.com"