Created
March 4, 2017 12:45
-
-
Save floehopper/4b1a4514e21d09b70cece55e18ccd68e to your computer and use it in GitHub Desktop.
Parse URLs from sitemap.xml
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' | |
response = get(sitemap_path) | |
doc = Nokogiri::XML(response.body) | |
namespace = 'http://www.sitemaps.org/schemas/sitemap/0.9' | |
locs = doc.xpath('//urlset:url//urlset:loc', 'urlset' => namespace) | |
urls = locs.map(&:text).map { |u| URI(u).path }.uniq |
This saved me some time 6 years later, thanks.
🙌 ❤️
This saved me some time 7 years later, thanks.
This saved me some time 7 years later, thanks.
🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This saved me some time 6 years later, thanks.