2010-06-15 5 views
0

나는 Twitter 사용자 이름을보고 나에게 위치를 알려주는 간단한 스크립트를 가졌다. 하지만 일부 사용자 이름이 존재하지 않고 오류가 발생합니다.구조 Nokogiri 오류

/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) 

감사합니다.

답변

0

은 간단한 구조 StandardError가 속임수를 썼는지 밝혀졌습니다.

1

큰 따옴표 안에 큰 따옴표를 넣으십시오!) (at_css에 대한 호출에 대한 작은 따옴표를 사용

my_file.puts "http://twitter.com/#{line} #{loc.at_css('.adr').text}"