Module: Html2rss

Defined in:
lib/html2rss.rb,
lib/html2rss/cli.rb,
lib/html2rss/url.rb,
lib/html2rss/html.rb,
lib/html2rss/error.rb,
lib/html2rss/config.rb,
lib/html2rss/status.rb,
lib/html2rss/article.rb,
lib/html2rss/channel.rb,
lib/html2rss/version.rb,
lib/html2rss/defaults.rb,
lib/html2rss/hash_util.rb,
lib/html2rss/selectors.rb,
lib/html2rss/auto_source.rb,
lib/html2rss/feed_result.rb,
lib/html2rss/feed_builder.rb,
lib/html2rss/config/schema.rb,
lib/html2rss/feed_pipeline.rb,
lib/html2rss/html/navigator.rb,
lib/html2rss/html/rendering.rb,
lib/html2rss/request_service.rb,
lib/html2rss/request_session.rb,
lib/html2rss/config/validator.rb,
lib/html2rss/feed_builder/rss.rb,
lib/html2rss/article/enclosure.rb,
lib/html2rss/auto_source/cleanup.rb,
lib/html2rss/auto_source/scraper.rb,
lib/html2rss/article/deduplicator.rb,
lib/html2rss/selectors/extractors.rb,
lib/html2rss/selectors/item_scope.rb,
lib/html2rss/auto_source/discovery.rb,
lib/html2rss/config/dynamic_params.rb,
lib/html2rss/request_session/pager.rb,
lib/html2rss/config/request_headers.rb,
lib/html2rss/feed_builder/json_feed.rb,
lib/html2rss/html/article_extractor.rb,
lib/html2rss/request_service/budget.rb,
lib/html2rss/request_service/policy.rb,
lib/html2rss/config/request_controls.rb,
lib/html2rss/request_service/context.rb,
lib/html2rss/auto_source/scraper/html.rb,
lib/html2rss/request_service/response.rb,
lib/html2rss/request_service/strategy.rb,
lib/html2rss/selectors/extractors/href.rb,
lib/html2rss/selectors/extractors/html.rb,
lib/html2rss/selectors/extractors/text.rb,
lib/html2rss/selectors/post_processors.rb,
lib/html2rss/auto_source/scraper/schema.rb,
lib/html2rss/config/selectors_validator.rb,
lib/html2rss/request_session/pager/base.rb,
lib/html2rss/auto_source/link_heuristics.rb,
lib/html2rss/auto_source/scraper/sitemap.rb,
lib/html2rss/config/auto_source_contract.rb,
lib/html2rss/feed_builder/json_feed/item.rb,
lib/html2rss/feed_builder/rss/stylesheet.rb,
lib/html2rss/feed_pipeline/auto_fallback.rb,
lib/html2rss/feed_pipeline/strategy_plan.rb,
lib/html2rss/html/rendering/pdf_renderer.rb,
lib/html2rss/selectors/extractors/static.rb,
lib/html2rss/config/multiple_feeds_config.rb,
lib/html2rss/feed_pipeline/runtime_policy.rb,
lib/html2rss/request_session/pager/offset.rb,
lib/html2rss/auto_source/discovery/sitemap.rb,
lib/html2rss/auto_source/scraper/microdata.rb,
lib/html2rss/html/navigator/text_extractor.rb,
lib/html2rss/html/rendering/audio_renderer.rb,
lib/html2rss/html/rendering/image_renderer.rb,
lib/html2rss/html/rendering/media_renderer.rb,
lib/html2rss/html/rendering/video_renderer.rb,
lib/html2rss/request_service/network_guard.rb,
lib/html2rss/auto_source/scraper/json_state.rb,
lib/html2rss/feed_builder/item_presentation.rb,
lib/html2rss/request_service/response_guard.rb,
lib/html2rss/request_session/pager/rel_next.rb,
lib/html2rss/selectors/extractors/attribute.rb,
lib/html2rss/selectors/post_processors/base.rb,
lib/html2rss/selectors/post_processors/gsub.rb,
lib/html2rss/auto_source/scraper/meta_oembed.rb,
lib/html2rss/request_service/blocked_surface.rb,
lib/html2rss/auto_source/scraper/schema/thing.rb,
lib/html2rss/request_service/faraday_strategy.rb,
lib/html2rss/request_service/puppet_commander.rb,
lib/html2rss/auto_source/scraper/microformats2.rb,
lib/html2rss/auto_source/scraper/semantic_html.rb,
lib/html2rss/auto_source/scraper/wordpress_api.rb,
lib/html2rss/request_session/pager/json_cursor.rb,
lib/html2rss/selectors/object_to_xml_converter.rb,
lib/html2rss/html/rendering/description_builder.rb,
lib/html2rss/request_session/pager/url_template.rb,
lib/html2rss/selectors/post_processors/template.rb,
lib/html2rss/html/article_extractor/id_generator.rb,
lib/html2rss/request_service/botasaurus_contract.rb,
lib/html2rss/request_service/botasaurus_strategy.rb,
lib/html2rss/request_service/local_file_strategy.rb,
lib/html2rss/selectors/post_processors/parse_uri.rb,
lib/html2rss/selectors/post_processors/substring.rb,
lib/html2rss/auto_source/discovery/dom_clustering.rb,
lib/html2rss/auto_source/scraper/schema/item_list.rb,
lib/html2rss/request_service/browserless_strategy.rb,
lib/html2rss/selectors/post_processors/parse_time.rb,
lib/html2rss/auto_source/discovery/list_candidates.rb,
lib/html2rss/html/article_extractor/date_extractor.rb,
lib/html2rss/request_session/pager/custom_selector.rb,
lib/html2rss/html/article_extractor/image_extractor.rb,
lib/html2rss/selectors/post_processors/sanitize_html.rb,
lib/html2rss/html/article_extractor/heading_extractor.rb,
lib/html2rss/auto_source/discovery/semantic_containers.rb,
lib/html2rss/html/article_extractor/category_extractor.rb,
lib/html2rss/auto_source/link_heuristics/anchor_signals.rb,
lib/html2rss/auto_source/link_heuristics/href_extractor.rb,
lib/html2rss/html/article_extractor/enclosure_extractor.rb,
lib/html2rss/selectors/post_processors/html_to_markdown.rb,
lib/html2rss/selectors/post_processors/markdown_to_html.rb,
lib/html2rss/auto_source/link_heuristics/path_classifier.rb,
lib/html2rss/auto_source/link_heuristics/text_classifier.rb,
lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb,
lib/html2rss/auto_source/link_heuristics/container_signals.rb,
lib/html2rss/auto_source/link_heuristics/destination_facts.rb,
lib/html2rss/auto_source/scraper/schema/category_extractor.rb,
lib/html2rss/auto_source/link_heuristics/container_assessor.rb,
lib/html2rss/request_service/puppet_commander/preload_runner.rb,
lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb,
lib/html2rss/auto_source/scraper/wordpress_api/posts_endpoint.rb,
lib/html2rss/auto_source/discovery/dom_clustering/group_scorer.rb,
lib/html2rss/request_service/puppet_commander/navigation_guards.rb,
lib/html2rss/auto_source/scraper/semantic_html/entry_deduplicator.rb,
lib/html2rss/auto_source/discovery/dom_clustering/overlap_resolver.rb,
lib/html2rss/selectors/post_processors/html_transformers/wrap_img_in_a.rb,
lib/html2rss/auto_source/scraper/wordpress_api/page_scope/date_archive_range.rb,
lib/html2rss/selectors/post_processors/html_transformers/transform_urls_to_absolute_ones.rb

Overview

rubocop:disable Metrics/ModuleLength -- Channel value object owns extract + freeze + Marshal

Defined Under Namespace

Modules: FeedBuilder, HashUtil, Html, Log Classes: Article, AutoSource, CLI, Channel, Config, Defaults, Error, FeedPipeline, FeedResult, NoFeedItemsExtracted, RequestService, RequestSession, Selectors, Status, Url

Constant Summary collapse

VERSION =

Current application version.

'0.24.0'

Class Method Summary collapse

Class Method Details

.auto_json_feed(url, strategy: :auto, items_selector: nil, max_redirects: nil, max_requests: 4, local_file_path: nil) ⇒ Hash

Scrapes the provided URL and returns a JSONFeed 1.1 hash.

Parameters:

  • url (String)

    source page URL

  • strategy (Symbol) (defaults to: :auto)

    request strategy to use

  • items_selector (String, nil) (defaults to: nil)

    optional selector hint for item extraction

  • max_redirects (Integer, nil) (defaults to: nil)

    optional redirect limit override

  • max_requests (Integer) (defaults to: 4)

    optional request budget override (default: 4 for sitemap sub-fetches)

  • local_file_path (String, nil) (defaults to: nil)

    optional local HTML file path

Returns:

  • (Hash)

    JSONFeed-compliant hash



98
99
100
101
102
103
104
105
106
# File 'lib/html2rss.rb', line 98

def self.auto_json_feed(url,
                        strategy: :auto,
                        items_selector: nil,
                        max_redirects: nil,
                        max_requests: 4,
                        local_file_path: nil)
  json_feed(build_auto_source_config(url:, strategy:, items_selector:, max_redirects:, max_requests:,
                                     local_file_path:))
end

.auto_source(url, strategy: :auto, items_selector: nil, max_redirects: nil, max_requests: 4, local_file_path: nil) ⇒ RSS::Rss

Scrapes the provided URL and returns an RSS object.

Parameters:

  • url (String)

    source page URL

  • strategy (Symbol) (defaults to: :auto)

    request strategy to use

  • items_selector (String, nil) (defaults to: nil)

    optional selector hint for item extraction

  • max_redirects (Integer, nil) (defaults to: nil)

    optional redirect limit override

  • max_requests (Integer) (defaults to: 4)

    optional request budget override (default: 4 for sitemap sub-fetches)

  • local_file_path (String, nil) (defaults to: nil)

    optional local HTML file path

Returns:

  • (RSS::Rss)

    generated RSS feed



79
80
81
82
83
84
85
86
# File 'lib/html2rss.rb', line 79

def self.auto_source(url,
                     strategy: :auto,
                     items_selector: nil,
                     max_redirects: nil,
                     max_requests: 4,
                     local_file_path: nil)
  feed(build_auto_source_config(url:, strategy:, items_selector:, max_redirects:, max_requests:, local_file_path:))
end

.config_from_yaml_file(file, feed_name = nil) ⇒ Hash{Symbol => Object}

Loads a feed configuration from YAML.

Parameters:

  • file (String)

    path to the YAML file

  • feed_name (String, nil) (defaults to: nil)

    optional feed name inside a multi-feed config

Returns:

  • (Hash{Symbol => Object})

    loaded configuration hash



33
34
35
# File 'lib/html2rss.rb', line 33

def self.config_from_yaml_file(file, feed_name = nil)
  Config.load_yaml(file, feed_name)
end

.configure {|config| ... } ⇒ Html2rss::Defaults

Configures global library defaults.

Yield Parameters:

Returns:



123
124
125
126
127
# File 'lib/html2rss.rb', line 123

def configure
  config = defaults.dup
  yield config
  @defaults = config.freeze
end

.defaultsHtml2rss::Defaults

Returns the global defaults instance.

Returns:



114
115
116
# File 'lib/html2rss.rb', line 114

def defaults
  @defaults ||= Defaults.new.freeze
end

.feed(raw_config) ⇒ RSS::Rss

Returns an RSS object generated from the provided configuration.

Parameters:

  • raw_config (Hash{Symbol => Object})

    feed configuration

Returns:

  • (RSS::Rss)

    generated RSS feed



53
54
55
# File 'lib/html2rss.rb', line 53

def self.feed(raw_config)
  feed_result(raw_config).to_rss
end

.feed_result(raw_config) ⇒ Html2rss::FeedResult

Returns an opaque, Marshal-cacheable result of one scrape.

Prefer this when the same scrape must render as RSS and JSON Feed (e.g. web cache).

Parameters:

  • raw_config (Hash{Symbol => Object})

    feed configuration

Returns:



44
45
46
# File 'lib/html2rss.rb', line 44

def self.feed_result(raw_config)
  FeedPipeline.new(raw_config).to_result
end

.json_feed(raw_config, feed_url: nil) ⇒ Hash

Returns a JSONFeed 1.1 hash generated from the provided configuration.

Parameters:

  • raw_config (Hash{Symbol => Object})

    feed configuration

  • feed_url (String, nil) (defaults to: nil)

    optional self URL for the feed (JSON Feed feed_url)

Returns:

  • (Hash)

    JSONFeed-compliant hash



63
64
65
# File 'lib/html2rss.rb', line 63

def self.json_feed(raw_config, feed_url: nil)
  feed_result(raw_config).to_json_feed(feed_url:)
end

.loggerObject

Returns the logger.

Returns:

  • (Object)

    the logger



131
132
133
# File 'lib/html2rss.rb', line 131

def logger
  defaults.logger
end

.logger=(logger) ⇒ Object

Parameters:

  • logger (Object)

    the new logger



137
138
139
# File 'lib/html2rss.rb', line 137

def logger=(logger)
  configure { |config| config.logger = logger }
end