Created
March 10, 2023 23:08
-
-
Save ezefranca/e407a5e2baeb6a648f3e710347550c7d to your computer and use it in GitHub Desktop.
This file contains 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
require 'nokogiri' | |
require 'open-uri' | |
Encoding.default_external = 'UTF-8' | |
query = params['query'] || 'banana' | |
page = params['page'].to_i || 0 | |
url = "https://www.continente.pt/pesquisa/?q=#{query}&start=#{page * 36}&srule=Continente%2003&pmin=0.01" | |
document = Nokogiri::HTML(open(url)) | |
search_items = document.css('div.productTile').map do |tile| | |
title = tile.css('a.pwc-tile--description').text.strip | |
price = tile.css('span.ct-price-formatted').text.strip | |
unit = tile.css('span.ct-tile--price-primary span.ct-m-unit').text.strip | |
img_url = tile.css('img.ct-tile-image').attr('data-src').value | |
brand = tile.css('p.pwc-tile--brand').text.strip | |
quantity = tile.css('p.pwc-tile--quantity').text.strip | |
destiny_url = tile.css('a.pwc-tile--description').attr('href').value | |
{ | |
title: title, | |
price: price, | |
unit: unit, | |
img_url: img_url, | |
brand: brand, | |
quantity: quantity, | |
destiny_url: destiny_url, | |
} | |
end | |
{ | |
query: query, | |
page: 0, | |
search_items: search_items, | |
url: url, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment