mirror of
https://github.com/moebooru/moebooru
synced 2025-08-22 09:57:31 +00:00
13 lines
343 B
Ruby
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
|