Method: Html2rss::AutoSource::Scraper::SemanticHtml.find_closest_selector

Defined in:
lib/html2rss/auto_source/scraper/semantic_html.rb

.find_closest_selector(current_tag, selector: 'a[href]:not([href=""])') ⇒ Nokogiri::XML::Node?

Finds the closest matching selector upwards in the DOM tree

Parameters:

  • current_tag (Nokogiri::XML::Node)

    The current tag to start searching from

  • selector (String) (defaults to: 'a[href]:not([href=""])')

    The CSS selector to search for

Returns:

  • (Nokogiri::XML::Node, nil)

    The closest matching tag or nil if not found

[View source]

66
67
68
# File 'lib/html2rss/auto_source/scraper/semantic_html.rb', line 66

def self.find_closest_selector(current_tag, selector: 'a[href]:not([href=""])')
  current_tag.at_css(selector) || find_closest_selector_upwards(current_tag, selector:)
end