Method to parse HTML document in Ruby?

后端 未结 4 2047
抹茶落季
抹茶落季 2020-11-29 09:03

like DOMDocument class in PHP, is there any class in RUBY (i.e the core RUBY), to parse and get node elements value from a HTML Document.

4条回答
  •  天涯浪人
    2020-11-29 09:57

    Ruby Cheerio - A jQuery style HTML parser in ruby. A most simplified version of Nokogiri for crawlers. This is the ruby version of most popular NodeJS package cheerio.

    Follow the link for a simple crawler example.

    gem install ruby-cheerio

    require 'ruby-cheerio'
    
    jQuery = RubyCheerio.new("

    h1_1

    h1_2

    ") jQuery.find('h1').each do |head_one| p head_one.text end # getting attribute values like jQuery. p jQuery.find('h1.one')[0].prop('h1','class') # function chaining similar to jQuery. p jQuery.find('body').find('h1').first.text

提交回复
热议问题