Class: HTTP::Response
Instance Method Summary collapse
-
#decoding_body ⇒ Object
解压并转码 body 数据.
- #get_date(str) ⇒ Object
-
#html ⇒ Object
def decoding_body.
- #json ⇒ Object
-
#parsing ⇒ Object
解析.
-
#readability ⇒ Object
通过readability 解析数据.
-
#results ⇒ Object
获取解析结果.
Instance Method Details
#decoding_body ⇒ Object
解压并转码 body 数据
5 6 7 |
# File 'lib/http_crawler/http/response.rb', line 5 def decoding_body @decoding_body ||= self.to_s end |
#get_date(str) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/http_crawler/http/response.rb', line 36 def get_date(str) time = Time.now case str when /^(\d{1,2})小时前$/ time = time - $1.to_i.hours when /^(\d{1,2})月(\d{1,2})日$/ time = Time.local(time.year, $1.to_i, $2.to_i) when /^(\d{4})年(\d{1,2})月(\d{1,2})日$/ time = Time.local($1.to_i, $2.to_i, $3.to_i) when /^(\d{1,2})月(\d{1,2})日[ ]{0,3}(\d{1,2}):(\d{1,2})$/ # 09月30日 12:04 time = Time.local(time.year, $1.to_i, $2.to_i, $3.to_i, $4.to_i) end return time end |
#html ⇒ Object
def decoding_body
11 12 13 |
# File 'lib/http_crawler/http/response.rb', line 11 def html @html ||= Nokogiri::HTML(decoding_body) end |
#json ⇒ Object
15 16 17 18 19 |
# File 'lib/http_crawler/http/response.rb', line 15 def json @json ||= JSON.parse(decoding_body) @json = JSON.parse(@json) if String === @json @json end |
#parsing ⇒ Object
解析
27 28 29 |
# File 'lib/http_crawler/http/response.rb', line 27 def parsing json end |
#readability ⇒ Object
通过readability 解析数据
22 23 24 |
# File 'lib/http_crawler/http/response.rb', line 22 def readability @readability ||= Readability::Document.new(decoding_body, {do_not_guess_encoding: true}) end |
#results ⇒ Object
获取解析结果
32 33 34 |
# File 'lib/http_crawler/http/response.rb', line 32 def results @results ||= parsing end |