0.0
The project is in a healthy, maintained state
A Ruby library that fetches pages with fast static HTTP requests and falls back to a headless browser when JavaScript rendering is required.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 3.12
>= 1.50
>= 0.22
>= 6.1
>= 3.18
>= 0.9

Runtime

>= 0.4
>= 0.21
>= 1.15
 Project Readme

HybridScraper

A Ruby library for web scraping that uses fast static HTTP requests first and falls back to a headless browser only when JavaScript rendering is required.

Installation

gem install hybrid_scraper
# optional, for JS fallback:
gem install ferrum

Or in your Gemfile:

gem "hybrid_scraper"
gem "ferrum" # optional

Usage

Basic fetch

require "hybrid_scraper"

client = HybridScraper.client
result = client.fetch("https://example.com")

puts result.mode   # :static or :browser
puts result.css("h1").map(&:text)

Force browser fallback with a selector

result = client.fetch("https://example.com", selector: ".product-price")
# If .product-price is missing in static HTML, Ferrum is used.

Force browser fallback with a block

result = client.fetch("https://example.com") do |doc|
  doc.css(".product-price").any?
end

Structured scraping

data = client.scrape("https://example.com", {
  title: "h1",
  prices: ".price",
  links: ->(doc) { doc.css("a").map { |a| a["href"] } }
})

Many URLs

rows = client.scrape_many(
  ["https://example.com/1", "https://example.com/2"],
  { title: "h1" }
)

Pagination

pages = client.paginate(
  "https://example.com/list",
  "a.next",
  limit: 5,
  fields: { title: "h2" }
)

Configuration

HybridScraper.configure do |c|
  c.user_agent   = "MyBot/1.0"
  c.timeout      = 20
  c.retries      = 5
  c.rate_limit   = 1.0  # seconds between requests
  c.headless     = true
end

Advanced features

Proxy

HybridScraper.configure do |c|
  c.proxy = "http://127.0.0.1:8080"
  c.proxy_username = "user"
  c.proxy_password = "pass"
end

Cookies & headers

result = client.fetch("https://example.com", cookies: { session: "abc" }, headers: { "Accept-Language" => "en" })

Anti-bot helpers

HybridScraper.configure do |c|
  c.rotate_user_agent = true
  c.user_agents = ["Mozilla/5.0 ...", "Mozilla/5.0 ..."]
  c.min_delay = 0.5
  c.max_delay = 2.0
  c.stealth = true
  c.respect_robots = true
end

Login (form-based)

client.login(
  "https://example.com/login",
  username: "me",
  password: "secret",
  username_selector: "input[name='email']",
  password_selector: "input[name='password']"
)

Export

rows = client.scrape_many(urls, { title: "h1" })
client.export_csv(rows, "out.csv")
client.export_json(rows, "out.json")

Security, privacy, and terms

  • Only scrape sites you are allowed to access. Respect robots.txt and the target site's Terms of Service.
  • Features like login, stealth, and proxy must be used in accordance with the target site's rules and applicable laws.
  • stealth adjusts browser headers/options; it is not intended to bypass anti-bot protections or access controls.
  • Never log or commit secrets. The library redacts common secret patterns in logs, but you are responsible for safe configuration.
  • SSRF protection validates URLs and redirects, but you should still restrict usage to trusted targets.

Notes

  • Ferrum is a runtime dependency for browser fallback.
  • Prefer official APIs when available.