-
-
Save anonymous/008b0215cd68e78c92e3 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' | |
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} | |
number = ALQDETALHESPB.count.to_i | |
numbers = Array.new(number) {|i| i+1 } | |
counter = numbers | |
foo = numbers.each_with_index.map do |number, idx| | |
"driver.find_element(:id, \"f04_000#{idx+1}\").send_keys(ALQDETALHESPB[#{idx+0}])" | |
end | |
puts foo.join("\n") | |
#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