Last active
January 7, 2022 14:49
-
-
Save caike/6678634 to your computer and use it in GitHub Desktop.
Basic script to parse WordPress XML. Although Nokogiri is the most popular lib for XML in Ruby these days, I've found Hpricot's API to be a lot easier to work with.
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
desc 'import from WordPress XML file' | |
task :import_from_wp => :environment do | |
require 'hpricot' | |
doc = Hpricot::XML(File.read('wp-export-file.xml')) | |
posts = (doc/:channel/:item) | |
posts.each do |post| | |
p "Post: #{post.at('link').inner_text}" | |
end | |
p "Total posts: #{posts.size}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part of this copied from https://gist.github.com/evanwalsh/6131008