Skip to content

Instantly share code, notes, and snippets.

@uzimith
Last active August 29, 2015 14:11
Show Gist options
  • Save uzimith/1a0536bcc033d8557754 to your computer and use it in GitHub Desktop.
Save uzimith/1a0536bcc033d8557754 to your computer and use it in GitHub Desktop.
unsubscribe all deleted channel with firefox.
require 'json'
class Client
def initialize
path = "client_secrets.json"
begin
json = open(path) do |io|
JSON.load(io)
end
@json = json
rescue => e
puts "#{e}"
end
end
def id
@json["id"]
end
def password
@json["password"]
end
end
# A sample Gemfile
source "https://rubygems.org"
gem "selenium-webdriver"
require "selenium-webdriver"
require_relative 'client.rb'
client = Client.new
driver = Selenium::WebDriver.for :firefox
#login
driver.navigate.to 'https://www.youtube.com/?hl=ja&gl=JP'
driver.find_element(:xpath, '//*[@id="yt-masthead-signin"]/button').click
driver.find_element(:name, 'Email').send_keys(client.id)
driver.find_element(:name, 'Passwd').send_keys(client.password)
driver.find_element(:xpath, '//*[@id="signIn"]').click
# list
elements = driver.find_elements(:css, '.guide-channels-list a')
links = elements.map {|e| e.attribute("href")}
links.each do |url|
next unless url.include?("channel")
driver.navigate.to url
title_element = driver.find_element(:class, 'branded-page-header-title')
if title_element.text.empty?
puts "remove"
driver.find_element(:xpath, '//*[@id="c4-primary-header-contents"]/div/span/button[1]').click
else
puts title_element.text
end
end
driver.quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment