即使遇到错误,我也想尝试运行我的代码。我将说明我认为我在下面得到错误的位置以及错误是什么:
require 'rubygems'
require 'simple_oauth'
require 'cloudsight'
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'open-uri'
require 'openssl'
require 'hpricot'
#ALCHEMY
file='C:\\Users\\ENTER USERNAME\\Desktop\\cloudsight.txt'
f = File.open(file, "r")
f.each_line {|line|
tstart = 'name"=>"'
tstop = '"'
term = line[/#{tstart}(.*?)#{tstop}/m, 1]
url = 'http://access.alchemyapi.com/calls'
service = '/text/TextGetRankedTaxonomy'
apikey = '?apikey=ENTER ALCHEMY API KEY'
thething = '&text='
termencoded = URI::encode(term)
fullurl = url + service + apikey + thething + termencoded
sleep 1
opener = open(fullurl, 'Accept-Encoding' => '') {|f| f.read }
#print opener
我想我在这一点上得到了错误。
lstart = '<label>/'
lstop = '</label>'
label = opener[/#{lstart}(.*?)#{lstop}/m, 1]
sleep 1
cstart = '<score>'
cstop = '</score>'
confidence = opener[/#{cstart}(.*?)#{cstop}/m, 1]
#data = label + ',' + confidence + ',' + line
print label
print confidence
print "\n"
}
这是我似乎得到的错误:
C:/Ruby21/lib/ruby/2.1.0/uri/common.rb:304:in `escape': undefined method `gsub' for nil:NilClass (NoMethodError)
关于如何传递错误/转义/或生成字符串的任何想法?