From 63314f4987d7acc8a39a3680320e339cc94da66b Mon Sep 17 00:00:00 2001 From: Matthias Hecker Date: Fri, 3 Apr 2020 13:51:57 +0200 Subject: plugin(search): fix wolfram and gdef, removed some this removes gcount and gtime from the search plugin, google no longer provides this information easily --- lib/rbot/core/utils/httputil.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index f7871e5b..e629becb 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -29,6 +29,12 @@ rescue LoadError => e EOC end +begin + require 'nokogiri' +rescue LoadError => e + error "No nokogiri library found, some features might not be available!" +end + # To handle Gzipped pages require 'stringio' require 'zlib' @@ -163,6 +169,15 @@ module ::Net return self.body_to_utf(self.decompress_body(partial)) end + + def xpath(path) + document = Nokogiri::HTML.parse(self.body) + document.xpath(path) + end + + def to_json + JSON::parse(self.body) + end end end @@ -649,7 +664,11 @@ class HttpUtil resp = get_response(uri, options, &block) raise "http error: #{resp}" unless Net::HTTPOK === resp || Net::HTTPPartialContent === resp - return resp.body + if options[:resp] + return resp + else + return resp.body + end rescue Exception => e error e end -- cgit v1.2.3