How to manipulate DOM with Ruby on Rails

前端 未结 3 1821
逝去的感伤
逝去的感伤 2021-02-03 14:40

As the title said, I have some DOM manipulation tasks. For example, I want to: - find all H1 element which have blue color. - find all text which have size 12px. - etc..

3条回答
  •  孤街浪徒
    2021-02-03 15:23

    To reliably sort out what color an arbitrary element on a webpage is, you would need to reverse engineer a browser (to accurately take into account stylesheets, markup hacks, broken tags, images, etc).

    A far easier approach would be to embed an existing browser such as gecko into a custom application of your making.

    As your spider would browse pages, it would pass them to your embedded instance of gecko where you could use getComputedStyle to pull what color an individual element happens to be.

    You originally mentioned wanting to use Ruby on Rails for this project, Rails is a framework for writing presentational applications and really a bad fit for a project like this.

    As a starting point, I'd recommend you check out RubyGnome, and in particular RubyGnome's Gtk::MozEmbed functionality.

提交回复
热议问题