Class: WebsiteUtils
- Inherits:
-
Object
- Object
- WebsiteUtils
- Defined in:
- lib/ruby_legendas_tv/website_utils.rb
Class Method Summary collapse
-
.get_article_urls(document) ⇒ Object
Returns a hash where key is link and value is the language of subtitle.
- .open_document(url, tries = 0) ⇒ Object
Class Method Details
.get_article_urls(document) ⇒ Object
Returns a hash where key is link and value is the language of subtitle
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_legendas_tv/website_utils.rb', line 5 def self.get_article_urls(document) unless document.nil? links = Hash.new items_div = document.css('div.gallery').css('article').children #puts items_div.inspect items_div.each{|link| links[link.css('a').attr('href').text] = link.css('img').attr('title').text } links end end |
.open_document(url, tries = 0) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby_legendas_tv/website_utils.rb', line 17 def self.open_document(url, tries=0) begin if tries > 3 return nil else status = Timeout::timeout(30) { document = Nokogiri::HTML(open(url, "User-Agent" => "Chrome/15.0.874.121")) return document } end rescue Timeout::Error puts 'Timeout error... Trying again' document = open_document(url, tries+1) return document end end |