0

我有一个关于 Ruby gem - Curb 的问题。我正在玩这个 gem 并拥有这段代码:

require 'curb'
require 'colorize'

def err(msg)
  puts
  puts msg.red
  puts 'HOWTO: '.white + './script.rb <domain>'.red
  puts
end

target = ARGV[0] || err("You forgot something....")

Curl::Easy.perform(target) do |curl| 
  curl.headers["User-Agent"] = "Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7.7) Gecko/20050421"
  curl.verbose = true
end

例如,当我在 google.com 上尝试时,我得到了这个标题(我没有从脚本中放入整个结果):

Host: google.com
Accept: */*
User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7.7) Gecko/20050421

* STATE: DO => DO_DONE handle 0x1c8dd80; (connection #0) 
* STATE: DO_DONE => WAITPERFORM handle 0x1c8dd80; (connection #0) 
* STATE: WAITPERFORM => PERFORM handle 0x1c8dd80; (connection #0) 
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Location: https://www.google.cz/?gfe_rd=cr&ei=2stTVO2eJumg8we6woGoCg
< Content-Length: 259
< Date: Fri, 31 Oct 2014 17:50:18 GMT
< Server: GFE/2.0
< Alternate-Protocol: 443:quic,p=0.01

我的问题,有什么办法,如何通过 Curb 只打印特定的标题?例如,我只想输出这个标题,如下所示:

Content-Type: text/html; charset=UTF-8
Location: https://www.google.cz/?gfe_rd=cr&ei=2stTVO2eJumg8we6woGoCg
Server: GFE/2.0

而且什么都没有了。有什么方法可以通过这个 gem 做到这一点吗?或者,如果您对如何使用其他宝石有任何想法,请告诉我。

4

1 回答 1

0

自己解析并不是最困难的事情。

这正是“ Get response headers from Curb ”的建议。

于 2014-10-31T18:36:04.893 回答