Skip to content

Instantly share code, notes, and snippets.

@bergfelipe
Created December 13, 2022 01:42
Show Gist options
  • Select an option

  • Save bergfelipe/486f1d1695e4a048eb6c7b5de87d7ff6 to your computer and use it in GitHub Desktop.

Select an option

Save bergfelipe/486f1d1695e4a048eb6c7b5de87d7ff6 to your computer and use it in GitHub Desktop.
nokogiri
#! /usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
# Fetch and parse HTML document
doc = Nokogiri::HTML(URI.open('https://www.imdb.com/chart/top/?ref_=nv_mv_250'))
table = doc.css('table.chart').css('tbody.lister-list')
open('filmes.csv', 'w') do |arquivo|
table.search('tr').each do |tr|
title = tr.css('td.titleColumn').css('a').text
note = tr.css('td.ratingColumn').css('strong').text
arquivo.puts %("#{title.chomp}";"#{note.chomp}")
next if tr['class'] == 'watchlistColumn'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment