Ruby on rails 拯救诺科吉里错误
我有一个简单的脚本,可以查看Twitter用户名并获取位置。但有些用户名不存在,我得到错误信息:Ruby on rails 拯救诺科吉里错误,ruby-on-rails,nokogiri,rescue,Ruby On Rails,Nokogiri,Rescue,我有一个简单的脚本,可以查看Twitter用户名并获取位置。但有些用户名不存在,我得到错误信息: /usr/lib/ruby/1.8/open-uri.rb:277:in `open_http': 404 Not Found (OpenURI::HTTPError) 我试着去救它,但我无法让它工作。有人能帮忙吗?谢谢 a = [] my_file = File.new("location.txt", 'a+') File.open('address.txt', 'r') do |f| whi
/usr/lib/ruby/1.8/open-uri.rb:277:in `open_http': 404 Not Found (OpenURI::HTTPError)
我试着去救它,但我无法让它工作。有人能帮忙吗?谢谢
a = []
my_file = File.new("location.txt", 'a+')
File.open('address.txt', 'r') do |f|
while line = f.gets
url = "http://twitter.com/#{line}"
doc = Nokogiri::HTML(open(url, 'User-Agent' => 'ruby'))
doc.css("#side #profile").each do |loc|
my_file.puts "http://twitter.com/#{line} #{loc.at_css(".adr").text}"
puts line
end
end
end
我还需要帮助挽救另一个错误:
twitter.rb:14: undefined method `text' for nil:NilClass (NoMethodError)
谢谢。在其他双引号内加上双引号!对at_css()的调用使用单引号:
结果是一个简单的错误起了作用
my_file.puts "http://twitter.com/#{line} #{loc.at_css('.adr').text}"