“syntax error, unexpected tIDENTIFIER, expecting $end”

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-26 04:24:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!