Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- require 'nokogiri'
- require 'open-uri'
- doc = Nokogiri::HTML(open('http://molestia.ponify.me:8062/index.html', 'User-Agent' => "Mozilla/5.0 Ruby/#{RUBY_VERSION}"))
- Benchmark.bm do |x|
- x.report("Full mapping:") {
- #begin full table=>hash mapping
- stream_data = {}
- doc.xpath('//table[3]/tr').each do |row|
- key = row.css('td')[0].content.strip.sub(':','').gsub(' ','_').downcase.to_sym
- value = row.css('td')[1].content
- stream_data[key] = value
- end
- #puts stream_data.inspect
- }
- x.report("Selected mapping:") {
- #begin selected table=>hash mapping
- stream_data = {}
- expected_prefixes = ["Stream Status", "Listener Peak", "Stream Title", "Current"]
- doc.xpath('//table[3]/tr').each do |row|
- next unless row.css('td')[0].content.start_with?(*expected_prefixes)
- key = row.css('td')[0].content.strip.sub(':','').gsub(' ','_').downcase.to_sym
- value = row.css('td')[1].content
- stream_data[key] = value
- end
- #puts stream_data.inspect
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement