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

13 lines
343 B
Ruby

module ExtractUrls
# Extract image URLs from HTML.
def extract_image_urls(url, body)
urls = []
Nokogiri::HTML(body).xpath("//a[@href]").each do |link|
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