Created
May 21, 2018 17:02
-
-
Save alexishida/a6370db47b69675ea3dd33c6a6754db6 to your computer and use it in GitHub Desktop.
Exemplo de webscraping usando nokogiri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env ruby | |
| require 'nokogiri' | |
| require 'open-uri' | |
| # Fetch and parse HTML document | |
| doc = Nokogiri::HTML(open('https://lista.mercadolivre.com.br/power-bank')) | |
| itens = [] | |
| doc.css('.results-item').each do |dados| | |
| item = { | |
| titulo: "", | |
| fraction: "", | |
| decimal: "" | |
| } | |
| dados.css('.main-title').each do |titulo| | |
| item[:titulo] = titulo.content | |
| end | |
| dados.css('.price__fraction').each do |fraction| | |
| item[:fraction] = fraction.content | |
| end | |
| dados.css('.price__decimals').each do |decimal| | |
| item[:decimal] = decimal.content | |
| end | |
| itens << item | |
| end | |
| puts itens |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment