我在实现一个简单的屏幕抓取器时遇到问题。基本脚本如下:
require 'selenium-webdriver'
width = 1024
height = 728
@websites = Array.new
file = open('websites.txt')
file.each_line { |line| @websites.push line }
@websites.each do |website|
d = Selenium::WebDriver.for :firefox
puts "Now going to:"+ " #{website}"
d.navigate.to website
d.execute_script %Q{
window.resizeTo(#{width}, #{height});
}
d.save_screenshot("#{website.gsub('http://', '')}"+".png")
d.quit
sleep 10
end
selenium 抛出的异常:
ruby keepwatch.rb
Now going to: http://www.example.com/
/Users/Big_Bird/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb:18:in `initialize': No such file or directory - www.example.com/ (Errno::ENOENT)
.png
from /Users/Big_Bird/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb:18:in `open'
from /Users/Big_Bird/.rvm/gems/ruby-1.9.2-p320/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb:18:in `save_screenshot'
from keepwatch.rb:29:in `block in <main>'
from keepwatch.rb:22:in `each'
from keepwatch.rb:22:in `<main>'
在这件事上我能得到任何帮助,我将不胜感激。