Skip to content

Instantly share code, notes, and snippets.

/foofoo.rb Secret

Created September 29, 2015 23:32
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/ff8f164e5a0d549cc4ab to your computer and use it in GitHub Desktop.
Save anonymous/ff8f164e5a0d549cc4ab to your computer and use it in GitHub Desktop.
#!/bin/env ruby
# encoding: utf-8
require 'pry'
require 'open-uri'
require 'nokogiri'
url = "http://www.tristar.eu/pt/Electr%C3%B3nica/Boombox/Radio_Stereo_CD/CD-1568/3/5277"
doc = Nokogiri::HTML(open(url))
ALQDETALHESPB = doc.xpath(' //*[(@id = "Gegevens")]//li').collect {|node| node.text.strip}
det1 = 'driver.find_element(:id, "f04_000'
det2 = '").send_keys(ALQDETALHESPB['
det3 = '])'
number = ALQDETALHESPB.count.to_i
numbers = Array.new(number) {|i| i+1 }
counter = numbers
# puts driver.find_element(:id,"add").click
counter.each do |counter|
counterx = det1 + counter.to_s + det2 + counter.to_s + det3
#puts driver.find_element(:id,"add").click
puts counterx
end
## but none of these are actualy sent to the interpreter,
## just printed on screen, if i manualy
## copy paste the lines bellow in my irb session, the data is correctly placed where i want it.
# driver.find_element(:id, "f04_0001").send_keys(ALQDETALHESPB[1])
# driver.find_element(:id, "f04_0002").send_keys(ALQDETALHESPB[2])
# driver.find_element(:id, "f04_0003").send_keys(ALQDETALHESPB[3])
# driver.find_element(:id, "f04_0004").send_keys(ALQDETALHESPB[4])
# driver.find_element(:id, "f04_0005").send_keys(ALQDETALHESPB[5])
# driver.find_element(:id, "f04_0006").send_keys(ALQDETALHESPB[6])
# driver.find_element(:id, "f04_0007").send_keys(ALQDETALHESPB[7])
# => [1, 2, 3, 4, 5, 6, 7]
# 2.2.1 :030 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment