Skip to content

Instantly share code, notes, and snippets.

@MurtzaM
Last active March 11, 2022 11:26
Show Gist options
  • Save MurtzaM/9673281 to your computer and use it in GitHub Desktop.
Save MurtzaM/9673281 to your computer and use it in GitHub Desktop.
Scrapes img alt tags from HTML using Ruby with Nokogiri gem
require 'nokogiri'
require 'open-uri'
#Scrapes img alt tags from specified URL
url = "CHANGE ME"
alt_tags = Array.new
doc = Nokogiri::HTML(open(url))
alt_tags = doc.css('img').map{ |i| i['alt'] }
#Prints out unique alt tags
puts alt_tags.uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment