0

我在实现一个简单的屏幕抓取器时遇到问题。基本脚本如下:

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>'

在这件事上我能得到任何帮助,我将不胜感激。

4

1 回答 1

2

尝试添加文件路径并从末尾删除 / (www.example.com/)。如果这不起作用,请尝试删除除文件名和扩展名之间的点之外的所有点。

例如 - d.save_screenshot("./screenshot.png")

于 2013-03-16T08:25:13.340 回答