-
-
Save anonymous/bac4fc41085ee2fc245a 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
#!/bin/env ruby | |
# encoding: utf-8 | |
require 'pry' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'pp' | |
url = "http://www.tristar.eu/pt/Electr%C3%B3nica/Boombox/Radio_Stereo_CD/CD-1568/3/5277" | |
doc = Nokogiri::HTML(open(url)) | |
#array | |
ALQDETALHESPB = doc.xpath(' //*[(@id = "Gegevens")]//li').collect {|node| node.text.strip} | |
#number of array items | |
number = ALQDETALHESPB.count.to_i | |
numbers = Array.new(number) {|i| i+1 } | |
counter = numbers | |
foo = numbers.each_with_index.map do |number, index| | |
driver.find_element(:id, \"f04_000#{index+1}\").send_keys(ALQDETALHESPB[#{index+0}]) | |
end | |
# 2.2.1 :012 > #array | |
# 2.2.1 :013 > ALQDETALHESPB = doc.xpath(' //*[(@id = "Gegevens")]//li').collect {|node| node.text.strip} | |
# => ["Rádio FM com sintonia PLL e 20 estações predefinidas", "Leitura Digital", "Com todas as funções de CD", "Aux-in", "Entrada para auriculares", "Potência: 2 x 3 Watt", "AC 230 V / Pilhas (não incluído)"] | |
# 2.2.1 :014 > | |
# 2.2.1 :015 > #number of array items | |
# 2.2.1 :016 > number = ALQDETALHESPB.count.to_i | |
# => 7 | |
# 2.2.1 :017 > numbers = Array.new(number) {|i| i+1 } | |
# => [1, 2, 3, 4, 5, 6, 7] | |
# 2.2.1 :018 > counter = numbers | |
# => [1, 2, 3, 4, 5, 6, 7] | |
# 2.2.1 :019 > | |
# 2.2.1 :020 > | |
# 2.2.1 :021 > foo = numbers.each_with_index.map do |number, index| | |
# 2.2.1 :022 > driver.find_element(:id, \"f04_000#{index+1}\").send_keys(ALQDETALHESPB[#{index+0}]) | |
# 2.2.1 :023?> end | |
# 2.2.1 :024?> | |
#i was hoping to get an error like "NameError: undefined local variable or method `driver' for main:Object" | |
#but instead i get the actual command printed on the screen like the folowing lines: | |
# driver.find_element(:id, "f04_0001").send_keys(ALQDETALHESPB[0]) | |
# driver.find_element(:id, "f04_0002").send_keys(ALQDETALHESPB[1]) | |
# driver.find_element(:id, "f04_0003").send_keys(ALQDETALHESPB[2]) | |
# driver.find_element(:id, "f04_0004").send_keys(ALQDETALHESPB[3]) | |
# driver.find_element(:id, "f04_0005").send_keys(ALQDETALHESPB[4]) | |
# driver.find_element(:id, "f04_0006").send_keys(ALQDETALHESPB[5]) | |
# driver.find_element(:id, "f04_0007").send_keys(ALQDETALHESPB[6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment