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|
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)
ありがとう。