1
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?

Selenium で Radiko を操作したい

Posted at

Selenium で Radiko を操作したかった

起動

[selenium向け] ChromeDriverをpipでインストールする方法(パス通し不要、バージョン指定可能) #Python - Qiita
ChromeDriverをpipでバージョン指定してインストールする手順 #Python - Qiita

import chromedriver_binary
import time

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys as keys
from selenium.webdriver.support.select import Select

# オプションを設定。画面を閉じないようにする
options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)

# TBSラジオのページを開く
driver.get("https://radiko.jp/#!/live/TBS")
sleep(1)

# 同意ボタンクリック
driver.find_element(By.CLASS_NAME, "btn--medium").click()
sleep(1)

# 再生するボタンクリック
driver.find_element(By.CLASS_NAME, "btn--primary").click()
sleep(1)

# 視聴者情報選択
driver.find_element(By.CLASS_NAME,"radio_button").click()
dropdown = driver.find_element(By.NAME, "birthYear")
select = Select(dropdown)
select.select_by_index(46) 

dropdown = driver.find_element(By.NAME, "birthMonth")
select = Select(dropdown)
select.select_by_index(5) 
driver.find_element(By.CLASS_NAME, "questionare-form_submit").click()

停止

PythonのSeleniumを使って、起動済みのブラウザを操作する。 #Python - Qiita

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options=options)
driver.close()

実行ファイル化

Pythonファイルをexe/app化する。 #PyInstaller - Qiita

最終的に 起動用.app と 停止用.app が出来上がりました。
image.png

動機

radiko、ふとした時に聴きたくなりつつ、仕事に戻るときにさっとオフにしたい。色々試行錯誤しているうちに Selenium であれこれやるちょうどいい教材になりました。

作業記録がてら以上です

1
0
0

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
1
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?