0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby NokogiriでRSSのパースが出来ない

Last updated at Posted at 2015-05-19

わからないことの備忘録。

RubyのNokogiriを使って、iTunesのRSSをパースしようとしたものの、xmlの中には値はあるのに、item_nodesのところはなぜか値が空っぽになっていて取得できない。

自分の想定では、xml.xpath('//entry')の部分でentryタグないの値をとってきて、その中のものを取得できると思って書いたのですが思い通りにいかず。

最終的にやりたいことはim:imageとかim:collectionの中身とかを扱いたいんだけど・・・・。

わからない・・・・

# -*- encoding: UTF-8 -*-
require 'nokogiri'
require 'open-uri'

url = 'https://itunes.apple.com/jp/rss/topsongs/limit=10/genre=27/xml'

xml = Nokogiri::XML(open(url).read)

item_nodes = xml.xpath('//entry')

p item_nodes

item_nodes.each do |item|
  puts "id:" + item.xpath('id').text
  puts "link:" + item.xpath('link').text
  puts "im:image" + item.xpath('im:image').text
end

簡単なヒントでもいいので、ご助言いただけると助かります。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?