2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-22 09:57:31 +00:00
moebooru/lib/extract_urls.rb

13 lines
345 B
Ruby
Raw Permalink Normal View History

module ExtractUrls
# Extract image URLs from HTML.
def extract_image_urls(url, body)
urls = []
Nokogiri::HTML(body).xpath("//a[@href]").each do |link|
2024-01-08 19:39:01 +09:00
urls += [ Addressable::URI.join("#{url}/", link[:href]).normalize.to_s ] if link[:href] =~ /\.(png|jpe?g)\z/i
end
urls
end
module_function :extract_image_urls
end