1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/local/bin/ruby require 'net/http' host = "www.smartmoney.com" link = "/eqsnaps/index.cfm?story=snapshot&symbol="+ARGV[0] begin # Create a new HTTP connection httpCon = Net::HTTP.new( host, 80 ) # Perform a HEAD request resp = httpCon.get( link, nil ) stroffset = resp.body =~ /class="price">/ subset = resp.body.slice(stroffset+14, 10) limit = subset.index('<') print ARGV[0] + " current stock price " + subset[0..limit-1] + " (from stockmoney.com)\n" end |
1 2 3 4 5 6 7 | [mtj@camus]$ ./stockprice.rb ibm ibm current stock price 79.28 (from stockmoney.com) [mtj@camus]$ ./stockprice.rb intl intl current stock price 21.69 (from stockmoney.com) [mtj@camus]$ ./stockprice.rb nt nt current stock price 2.07 (from stockmoney.com) [mtj@camus]$ |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |