2014-10-31 43 views
0

我有一個關於Ruby 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 

我的問題,有沒有什麼辦法,如何打印只有特定的標題通過路邊?例如,我只想輸出這個標題,如下所示:

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

而且什麼都沒有了。有沒有如何通過這個寶石做到這一點?或者,如果你有任何想法如何使用另一個寶石做到這一點,讓我知道。

回答

0

這不是最困難的,只是你自己分析它的事情。

這正是「Get response headers from Curb」所提出的。

+0

不要使用像「這個StackOverflow的答案」錨文本。相反,使用合理的描述性內容,讓人們更多地瞭解他們點擊的內容。請參閱「[不要使用」點擊此​​處作爲鏈接文本](http://www.w3.org/QA/Tips/noClickHere)「以獲取更多信息。 SO使得這很容易。看到你的答案編輯。 – 2014-10-31 21:03:52