2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-29 04:57:47 +00:00
moebooru/lib/extract_urls.rb

16 lines
348 B
Ruby
Raw Normal View History

2012-07-06 09:25:49 -07:00
require 'nokogiri'
module ExtractUrls
# Extract image URLs from HTML.
def extract_image_urls(url, body)
urls = []
2012-07-06 09:25:49 -07:00
Nokogiri::HTML(body).xpath('//a[@href]').each do |link|
2012-08-26 07:21:49 -07:00
urls += [URI.join("#{url}/", link[:href]).to_s] if link[:href] =~ /\.(png|jpe?g)\z/i
end
return urls
end
module_function :extract_image_urls
end