Created
June 7, 2014 05:56
-
-
Save taktamur/d8145675e49d2e7bf716 to your computer and use it in GitHub Desktop.
WWDC2014のビデオ一覧をmarkdown形式のリストに変換するrubyスクリプト
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
| # WWDC2014のビデオ一覧をスクレーピングして、markdown形式のリストで出力するスクリプト | |
| # ruby ./wwdc2014_video.rb > wwdc2014_video_list.md5 | |
| # | |
| # 参考にしたサイト: | |
| # http://morizyun.github.io/blog/ruby-nokogiri-scraping-tutorial/ | |
| # http://d.hatena.ne.jp/otn/20090509/p1 | |
| require 'open-uri' | |
| require 'nokogiri' #gem install nokogiri | |
| url = 'https://developer.apple.com/videos/wwdc/2014/' | |
| charset = nil | |
| html = open(url) do |f| | |
| charset = f.charset | |
| f.read | |
| end | |
| doc = Nokogiri::HTML.parse(html, nil, charset) | |
| # タイトルを表示 | |
| p doc.title | |
| doc.xpath('//li[@class="session"]').each do |node| | |
| # tilte | |
| title = node.at('[@class="title"]').inner_text | |
| link_ary = [] | |
| # ↓xpathで".//"としないと、親からも探してしまうよう。 | |
| node.xpath('.//p[@class="download"]').xpath('.//a').each do |link| | |
| name = link.inner_text | |
| if name=="HD" || name=="PDF" || name=="SD" then | |
| url = link.attribute('href').value | |
| link_ary.push "[#{name}](#{url})" | |
| end | |
| end | |
| puts "- #{title} #{link_ary.join(" ")} \n\n" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment