Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2015 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5b1aaedfe2adab9b1f17 to your computer and use it in GitHub Desktop.
Save anonymous/5b1aaedfe2adab9b1f17 to your computer and use it in GitHub Desktop.
#!/bin/env ruby
# encoding: utf-8
require 'open-uri'
require 'nokogiri'
#downcase com acentos e afins
require 'unicode_utils'
#url = ARGV[0]
#cat = ARGV[1]
url = "http://www.sex4fun.pt/pt/3042-anel-vibratório-butterfly-black-8714273058850.html"
#url2 = url.tr(
"ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
data = Nokogiri::HTML(open(url))
nome1 = data.css('.span8 h1').text
nome = UnicodeUtils.downcase(nome1).to_s.capitalize
ref = data.xpath('//*[(@id = "product_reference")]//*[contains(concat( " ", @class, " " ), concat( " ", "editable", " " ))]')
des1 = data.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "page-product-box", " " ))]//p')
img = data.css('.span4 ul a').map{ |a| [a['href']] }[0, 9].to_s.tr('"','')
fab1 = data.xpath ('//*[contains(concat( " ", @class, " " ), concat( " ", "lnk_img", " " ))]//strong')
fab2 = fab1.text
fab3 = UnicodeUtils.downcase(fab2)[1..-1].to_s.capitalize
#puts '"' + nome + '"'
#puts ref.text
#puts img.to_s.tr('[] ','')
#puts des1[0..-3].to_s
#puts fab3
puts '0' + '~' + '1000' + '~' + '"' + nome + '"' + '~' + '"' + ref.text + '"' + '~' + '"' + img.to_s.tr('[] ','') + '"' + '~' + '"' + des1[0..-3].to_s + '"' + '~' + '"' + fab3 + '"' + '~' + '"' + cat + '"' + '~' + '"' + ref.text + '"' + '~' + '"' + nome + ' - ' + fab3 + '"' + '~' + '"' + nome + ' - ' + fab3 + '"'+ '~' + '"' + nome + '"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment