Project

html_entry

0.0
No commit activity in last 3 years
No release in over 3 years
A simple gem which allows to organize fetching entries \ from plain HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0
 Project Readme

HTML Entries

This Ruby gem may help to fetch entries data from HTML by provided intructions.

Installation

Console:

$ gem install html_entry

Gemfile:

gem 'html_entry', '~> 0.1.0'

Using

Extended examples

Please take a look an extended version of "Quick Start" in the file tests/example/fetch_url.rb.

Please review tests to get different examples in these files:

Quick Start

This example may show how to fetch TOP questions from https://stackoverflow.com/ home page.

require 'pp'
require 'nokogiri'
require 'open-uri'
require 'html_entry'

fetcher              = HtmlEntry::PageFetcher.new
fetcher.instructions = {
    # This block can be fetched by using CSS selector contains an entry (or entries).
    # There are might be several blocks, as in this example.
    block: {
        type:     :selector,
        selector: '#question-mini-list .question-summary',
    },
    # Further, we have to describe entity attributes
    entity:
           [
               # If fetched node/s contains several attributes data,
               # you may describe all of them.
               # In this example: question "summary" and "url".
               {
                   selector: '.summary h3 a',
                   data:     {
                       summary: {},
                       url:     {
                           type:      :attribute,
                           attribute: 'href',
                       },
                   }
               },
               {
                   selector: '.votes > .mini-counts > span',
                   data:     {
                       votes: {
                           filter: :to_i
                       }
                   }
               },
           ]
}

items = fetcher.fetch Nokogiri::HTML(
    open('https://stackoverflow.com/')
)

# show items in terminal
items.each do |item|
  puts <<-OUTPUT
Question: "#{item[:summary]}"
votes:    #{item[:votes]}

OUTPUT
end
puts 'Element data:'
puts
pp items.last

Output

Question: "Can't see the alerts I created on Azure Portal"
votes:    4

[ ... ]

Element data:

{:summary=>"Scrapy on aws ec2 ubuntu redirect for booking.com",
 :url=>"/questions/52056897/scrapy-on-aws-ec2-ubuntu-redirect-for-booking-com",
 :votes=>2,
}