“语法错误,意外的 tIDENTIFIER,期待 $end" [英] "syntax error, unexpected tIDENTIFIER, expecting $end"
本文介绍了“语法错误,意外的 tIDENTIFIER,期待 $end"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根据这个教程编写了这个脚本.
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
我不断收到此错误:
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?
推荐答案
很可能您在 URL 中有一个非 ASCII 字符.
most likely you have a non ASCII char in URL.
尝试添加
# encoding: UTF-8
作为aaa.rb
所以它看起来像:
# encoding: UTF-8
require 'nokogiri'
require 'open-uri'
这篇关于“语法错误,意外的 tIDENTIFIER,期待 $end"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文