-
-
Save anonymous/a6f55e51e7677c73a6f6fe861c32b24f to your computer and use it in GitHub Desktop.
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
#for each entry in mel array i want him to to all this IF the lenght of "titulo" is greater than 1 or is 1 | |
# if it isn't, i want him to skip the titulo, tipo, specs, roda.. and just print "no titulo avaiable" | |
#sometimes it works, some it spits out "NoMethodError: undefined method `gsub' for nil:NilClass" related to the specs | |
# declaration ( specs = titulo.split.first.gsub('X','R') ) so, why is it going there if the titulo is less than 1 ?... | |
mel.each do |mel| | |
if mel.css('.product-description-title').length >= 1 | |
titulo = mel.css('.product-description-title').text | |
tipo = mel.css('.product-description-title').text.match(' \d{2}[A-Z].*').to_s.strip | |
specs = titulo.split.first.gsub('X','R') | |
roda = specs.split("R")[1] | |
diamt = specs.split("/").first | |
altura = specs.split("R")[0].split("/")[1] | |
marca = mel.css('.product-logo')[0]['src'][7..-1].split("/").last.gsub('.png','').capitalize | |
if mel.css('.product-price .btn-price') | |
pvp = "Sem" | |
else | |
pvp = mel.css('.btn-price')[0].text.to_s | |
end | |
stock = mel.css('.product-stock-button')[1].text.to_s[1..-1] | |
taggasto = mel.css('.product-label-gasolinera').text | |
tagseguro = mel.css('.product-label-lluvia').text | |
tagdbs = mel.css('.product-label-sonido').text.gsub('DB','') | |
velocidade = mel.css('.product-description-title').text.split.last.delete('0-9') | |
ean = "sem fonte" | |
fotourl = "mel.css('.product-image img')[0]['src'].gsub('articulos128','articulosBIG')" | |
codigo = fotourl.reverse.split("/").first.reverse[0..-5] | |
fonte = "http://www.gruposoledad.com/b2b/new/index.html" | |
marcatmp = marca.upcase | |
modelo = titulo.split.drop(1).join(" ").gsub("#{tipo}","").strip.gsub("#{marcatmp}","").strip | |
site = "grupoandres.com" | |
datetime= Time.now.strftime("%F %T") | |
else | |
puts "no titulo avaiable" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment