Hi folks!
I have an only-5-lines code above project,
require ‘Nokogiri’
require ‘open-uri’
cagometro = Nokogiri::HTML(URI.open(“http://www.cagometro.com/”))
cagadas = cagometro.xpath("")
puts cagadas
And I’m getting the error
Traceback (most recent call last):
4: from parser.rb:4:in <main>' 3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10-x64-mingw32/lib/nokogiri/xml/searchable.rb:154:in xpath’
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10-x64-mingw32/lib/nokogiri/xml/searchable.rb:179:in xpath_internal' 1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10-x64-mingw32/lib/nokogiri/xml/searchable.rb:198:in xpath_impl’
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.10-x64-mingw32/lib/nokogiri/xml/searchable.rb:198:in `evaluate’: ERROR: Invalid expression: (Nokogiri::XML::XPath::SyntaxError)
Since the error is mentioning searchable.rb in nokogiri project, and is not mentioning any line of my own code, I’m thinking that this can be a nokogiri’s bug?
There is something that I can do by my side to avoid this?
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nokogiri-talk/41484ffc-c8ad-47b3-b927-6c17ecb366f7n%40googlegroups.com.
require "open-uri" doc = Nokogiri::HTML(URI.open("http://www.cagometro.com/")) doc.css('div').each do |node| puts node.text end doc.xpath('.//div').each do |node| puts node.text endThis walks through each div on the page and print out the text contents of it (there are 12 div nodes on that page). Nothing fancy. Now, let's say we want only H2s that fall within a div do this:
require "open-uri" doc = Nokogiri::HTML(URI.open("http://www.cagometro.com/"))
puts 'From css:' doc.css('div > h2').each do |node| puts node.text end puts 'From xpath:' doc.xpath('.//div/h2').each do |node| puts node.text end
require "nokogiri" require "open-uri" doc = Nokogiri::HTML(URI.open("http://www.cagometro.com/")) puts 'From css:' doc.css('div > h2[@class="site-description"]').each do |node| puts node.text end puts 'From xpath:' doc.xpath('.//div/h2[@class="site-description"]').each do |node| puts node.text endAgain nothing fancy here, and the results are: