Created
April 19, 2014 14:36
-
-
Save kazuph/11086227 to your computer and use it in GitHub Desktop.
まとめからgif画像のURLを抽出するだけのスクリプト
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 "mechanize" | |
class BijoGifUrl | |
class << self | |
def execute() | |
new().urls | |
end | |
end | |
def initialize | |
@url = 'http://matome.naver.jp/odai/2128080390457574601' | |
@agent = Mechanize.new | |
@agent.user_agent_alias = "Mac Safari" | |
@agent.max_history = 1 | |
end | |
def urls | |
item_urls.map{|url| gif_url(url) }.flatten | |
end | |
def item_urls | |
(1..4).map{|index| | |
page(@url + '?&page='+index.to_s) | |
.search('p.mdMTMWidget01ItemImg01View>a') | |
.map{|url| format_url url} | |
}.flatten | |
end | |
def gif_url(url) | |
page(url).search('p.mdMTMEnd01Img01>a').map{|url| format_url url} | |
rescue => e | |
nil | |
end | |
private | |
def page(url) | |
@agent.get(url) | |
end | |
def format_url(url) | |
url.attributes['href'].value | |
end | |
end | |
if __FILE__ == $0 | |
urls = BijoGifUrl.execute | |
puts urls | |
end |
Author
kazuph
commented
Apr 19, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment