Skip to content

Instantly share code, notes, and snippets.

@Papillard
Last active January 11, 2018 10:42
Show Gist options
  • Save Papillard/5c03de42f098704e379de59a44968c34 to your computer and use it in GitHub Desktop.
Save Papillard/5c03de42f098704e379de59a44968c34 to your computer and use it in GitHub Desktop.
Scraping Etsy - Reboot batch #100
require 'open-uri'
require 'nokogiri'
puts "Quelle catégorie t'intéresse?"
category = gets.chomp
url = "https://www.etsy.com/search?q=#{category}"
file = open(url)
html_text = file.read
doc = Nokogiri::HTML(html_text)
# Cas simple: on trouve un tableau de balises directement
doc.search('.currency-value').each do |currency_box|
p currency_box.text
end
# Cas compliqué: on trouve un tableau de nouveaux blocs de HTML, dans lesquels on va devoir chercher à nouveau
doc.search('.v2-listing-card').each do |element|
p element.search('.text-body')[0].text.strip
p element.search('.currency-value')[0].text
p element.search('img')[0]["src"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment