Skip to content

Instantly share code, notes, and snippets.

@panchiga
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panchiga/62d1eb2b2eb378a2b016 to your computer and use it in GitHub Desktop.
Save panchiga/62d1eb2b2eb378a2b016 to your computer and use it in GitHub Desktop.
require "selenium-webdriver"
print "input site url: "
plain_url = gets.to_s.chop
print "input PERFECT title: "
title = gets.to_s.chop
url_title = title.gsub(" ","+")
url = plain_url+"/search/?search_id="+url_title
stories = 25
start_story = 1
end_story = 25
#何話分の話が見たいのか
loop do
print "input 1 or 2
1: 1-25
2: chose own
"
flag = gets.chop.to_i
if flag == 2
print "input start: "
start_story = gets.chop.to_i
print "input end: "
end_story = gets.chop.to_i
stories = end_story - start_story
elsif flag == 1
break
else
print "please, "
next
end
if stories > 0
break
end
puts "oops! one more input"
next
end
puts url
#seleniumっぽい部分
driver = Selenium::WebDriver.for :safari
driver.navigate().to url
movie_arr = Array.new
num = Array.new
#数字を作る
stories.times do |i|
if (i + start_story) < 10
num.push("0" + (i + start_story).to_s)
else
num.push((i + start_story).to_s)
end
end
now_story = start_story
#main loop
10.times do |page|
elements = driver.find_elements(:xpath, "//*[contains(concat(' ',normalize-space(@class),' '), ' videoTitle ')]/a")
#get title url and push movie_arr
elements.each do |element|
stories.times do |i|
if (element.text.index("#{title} #{num[i]}") != nil)
#puts element.text
movie_arr[i + start_story] = element.attribute("href")
break
end
end
end
#puts movie_arr
#ちゃんと配列に格納してなかった時にやり直すところ
if movie_arr[now_story] == nil
next_href = plain_url + "/search/#{page + 2}/?search_id=#{url_title}"
driver.navigate.to next_href
next
end
#1話ずつ再生していくところ
movie_arr.size.times do |i|
if(movie_arr[i + start_story] != nil)
now_story += 1
driver.navigate.to movie_arr[i + start_story]
#1回分の時間
sleep 24 * 60
else
next
end
end
#全部再生が終了した時に抜ける
puts "--------E--N--D--------"
break
end
driver.quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment