Forked from MurtzaM/Img Alt Tag Scraper using Nokogiri
Created
March 11, 2022 11:26
Scrapes img alt tags from HTML using Ruby with Nokogiri gem
This file contains hidden or 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