Last active
March 11, 2022 11:26
-
-
Save MurtzaM/9673281 to your computer and use it in GitHub Desktop.
Scrapes img alt tags from HTML using Ruby with Nokogiri gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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