问题
I put together this script based on this tutorial.
require 'nokogiri'
require 'open-uri'
url = "http://sfbay.craigslist.org/sby/jjj/"
data = Nokogiri::HTML(open(url))
puts data.at_css('.itempn').text
puts data.at_css('.itemcg').text
I keep getting this error:
Macintosh:nokogiri rgrush$ ruby aaa.rb
aaa.rb:1: syntax error, unexpected tIDENTIFIER, expecting $end
url = "http://sf...
^
Any ideas? Could it be that one of my dependencies is out of date?
回答1:
most likely you have a non ASCII char in URL.
try adding
# encoding: UTF-8
as first line of aaa.rb
so it will look like:
# encoding: UTF-8
require 'nokogiri'
require 'open-uri'
来源:https://stackoverflow.com/questions/13753601/syntax-error-unexpected-tidentifier-expecting-end