{"id":6503,"date":"2014-04-19T04:41:45","date_gmt":"2014-04-19T04:41:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/19\/nokogiricsssyntaxerror-when-rails-model-method-called-from-rails-console-but-runs-fine-when-i-copy-and-past-the-method-into-the-rails-console-collection-of-common-programming-errors\/"},"modified":"2014-04-19T04:41:45","modified_gmt":"2014-04-19T04:41:45","slug":"nokogiricsssyntaxerror-when-rails-model-method-called-from-rails-console-but-runs-fine-when-i-copy-and-past-the-method-into-the-rails-console-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/19\/nokogiricsssyntaxerror-when-rails-model-method-called-from-rails-console-but-runs-fine-when-i-copy-and-past-the-method-into-the-rails-console-collection-of-common-programming-errors\/","title":{"rendered":"Nokogiri::CSS::SyntaxError when rails model method called from rails console, but runs fine when I copy and past the method into the rails console-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m using Nokogiri in Rails 3.2.11 to do some screen scraping. I have this one very long method that when I copy and paste line by line into the rails console it runs flawlessly, but when I call it in the console form my model file, it breaks, sending this error: Nokogiri::CSS::SyntaxError: unexpected &#8216;$&#8217; after &#8221;<\/p>\n<p>Here&#8217;s the method (it&#8217;s 2, the first calls the second). Any help at all would be much appreciated:<\/p>\n<pre><code>def self.recurse_craigs(add = 'o')\n  years = \"#{MIN_YR}%7C05%7C#{MIN_YR+1}%7C06%7C#{MIN_YR+2}%7C07%7C#{MIN_YR+3}%7C08%7C#{MIN_YR+4}%7C09%7C#{MIN_YR+5}%7C#{MIN_YR+6}%7C#{MIN_YR+7}\"\n  CraigsLocalSite.all.each do |site|\n    url = \"http:\/\/#{site.city_for_url}.craigslist.org\/search\/ct#{add}?zoomToPosting=&amp;altView=&amp;query=#{years}&amp;srchType=T&amp;minAsk=#{MIN_PRICE}&amp;maxAsk=#{MAX_PRICE}\"\n    get_craigs_page(url, site, add)\n  end\nend\n\nprivate\n\n\ndef self.get_craigs_page(url, craigs_site, add, recursion_level = 0)\n  if add == 'o'\n    owner = true\n  elsif add == 'd'\n    dealer = true\n  end\n  dqers = ['rebuil', 'salvag', 'salvaj', 'rebil', 'ribil', 'over payment', 'take over', 'payments']\n  begin\n    Timeout::timeout(10) do\n      @doc = Nokogiri::HTML(open(url))\n    end\n  rescue\n  end\n  new_posts = 0\n  if defined? @doc\n    @doc.css('.row').each do |row|\n      #### DO SOME STUFF, IRRELEVANT BECAUSE THIS IS WHERE METHOD BREAKS\n<\/code><\/pre>\n<p>Here&#8217;s the error call stack:<\/p>\n<pre><code>Nokogiri::CSS::SyntaxError: unexpected '$' after ''\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/css\/parser_extras.rb:87:in `on_error'\n  from (eval):3:in `_racc_do_parse_c'\n  from (eval):3:in `do_parse'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/css\/parser_extras.rb:62:in `parse'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/css\/parser_extras.rb:79:in `xpath_for'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/css.rb:24:in `xpath_for'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node.rb:210:in `block in css'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node.rb:209:in `map'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node.rb:209:in `css'\n  from [app path]\/app\/models\/feed_entry.rb:348:in `block in get_craigs_page'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node_set.rb:239:in `block in each'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node_set.rb:238:in `upto'\n  from [gempath]\/nokogiri-1.4.7\/lib\/nokogiri\/xml\/node_set.rb:238:in `each'\n  from [app path]\/app\/models\/feed_entry.rb:335:in `get_craigs_page'\n  from [app path]\/app\/models\/feed_entry.rb:311:in `block in recurse_craigs'\n  from [app path]\/app\/models\/feed_entry.rb:309:in `each'\n  from [app path]\/app\/models\/feed_entry.rb:309:in `recurse_craigs'\n  from (irb):1\n  from [gempath]\/railties-3.2.11\/lib\/rails\/commands\/console.rb:47:in `start'\n  from [gempath]\/railties-3.2.11\/lib\/rails\/commands\/console.rb:8:in `start'\n  from [gempath]\/railties-3.2.11\/lib\/rails\/commands.rb:41:in `'\n  from script\/rails:6:in `require'\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using Nokogiri in Rails 3.2.11 to do some screen scraping. I have this one very long method that when I copy and paste line by line into the rails console it runs flawlessly, but when I call it in the console form my model file, it breaks, sending this error: Nokogiri::CSS::SyntaxError: unexpected &#8216;$&#8217; after [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6503","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6503"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6503\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}