Sebastian Delgado Sebastian Delgado - 1 year ago 71
Ruby Question

How to scrap only one specific ul with nokogiri?

I'm trying to get only the second ul element of this page, which is all the events list.

this is what i have right now:

require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML(open('', {ssl_verify_mode: 0}))

doc.css('ul').each do |link|
puts link.content

the UL that i need is the second one present on the whole html document, how can i select only that one ?

Thanks for reading.

Answer Source

Try this


or if you want to use CSS selectors only

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download