initial commit
commit
94d7e75215
|
@ -0,0 +1 @@
|
||||||
|
app/ss/
|
|
@ -0,0 +1,122 @@
|
||||||
|
# main.py
|
||||||
|
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
import time,os
|
||||||
|
|
||||||
|
# 変数初期化 ********************************************************************
|
||||||
|
profile_dir = "/tmp/profile"
|
||||||
|
username = os.environ["RAKUTENID"]
|
||||||
|
password = os.environ["RAKUTENPW"]
|
||||||
|
waittime = 10
|
||||||
|
target_url = "https://channel.rakuten.co.jp/"
|
||||||
|
welcome_btn_css = 'button[data-ratid="welcome_pg1_ok"]'
|
||||||
|
login_btn_css = 'button[data-ratid="login_button"]'
|
||||||
|
user_textarea_css = 'input[aria-label="ユーザIDまたはメールアドレス"]'
|
||||||
|
passwd_textarea_css = 'input[type="password"]'
|
||||||
|
channel_btn_css = 'button[data-ratid="select_program_now_playing"]'
|
||||||
|
# ******************************************************************************
|
||||||
|
|
||||||
|
def gen_driver():
|
||||||
|
"""
|
||||||
|
WebDriver 生成
|
||||||
|
"""
|
||||||
|
options = webdriver.ChromeOptions()
|
||||||
|
options.add_argument("--window-size=1920,1080")
|
||||||
|
options.add_argument("--user-data-dir=" + profile_dir )
|
||||||
|
|
||||||
|
driver = webdriver.Remote(
|
||||||
|
command_executor="http://selenium:4444/wd/hub",
|
||||||
|
options=options
|
||||||
|
)
|
||||||
|
return driver
|
||||||
|
|
||||||
|
def init_profiles():
|
||||||
|
"""
|
||||||
|
初回ログイン等
|
||||||
|
"""
|
||||||
|
driver = gen_driver()
|
||||||
|
|
||||||
|
# Begin
|
||||||
|
driver.get(target_url)
|
||||||
|
|
||||||
|
# ロード待ち
|
||||||
|
wait = WebDriverWait(driver, 10)
|
||||||
|
element = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
|
||||||
|
|
||||||
|
driver.save_screenshot('./ss/ss.png')
|
||||||
|
|
||||||
|
# Welcomeメッセージを閉じる
|
||||||
|
try:
|
||||||
|
welcom_button = driver.find_element(By.CSS_SELECTOR, welcome_btn_css)
|
||||||
|
welcom_button.click()
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ログイン試行
|
||||||
|
try:
|
||||||
|
# ログインボタン押下
|
||||||
|
login_button = driver.find_element(By.CSS_SELECTOR, login_btn_css)
|
||||||
|
login_button.click()
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# ユーザID入力
|
||||||
|
user = driver.find_element(By.CSS_SELECTOR, user_textarea_css)
|
||||||
|
user.send_keys(username)
|
||||||
|
|
||||||
|
driver.save_screenshot('./ss/ss_usrname.png')
|
||||||
|
user.send_keys(Keys.ENTER)
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# パスワード入力
|
||||||
|
passwd = driver.find_element(By.CSS_SELECTOR, passwd_textarea_css)
|
||||||
|
passwd.send_keys(password)
|
||||||
|
driver.save_screenshot('./ss/ss_password.png')
|
||||||
|
passwd.send_keys(Keys.ENTER)
|
||||||
|
time.sleep(10)
|
||||||
|
driver.save_screenshot('./ss/ss_password2.png')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
driver.save_screenshot('./ss/ss2.png')
|
||||||
|
|
||||||
|
# Coockie 取得
|
||||||
|
cookies = driver.get_cookies()
|
||||||
|
|
||||||
|
# End
|
||||||
|
driver.quit()
|
||||||
|
|
||||||
|
def watching_rch():
|
||||||
|
# Rch アクセス
|
||||||
|
driver = gen_driver()
|
||||||
|
driver.get(target_url)
|
||||||
|
|
||||||
|
# ロード待ち
|
||||||
|
wait = WebDriverWait(driver, 10)
|
||||||
|
element = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
|
||||||
|
|
||||||
|
# 10秒待機
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
for i in range(0,8):
|
||||||
|
channel_btns = driver.find_elements(By.CSS_SELECTOR, channel_btn_css)
|
||||||
|
channel_btn = channel_btns[i]
|
||||||
|
channel_btn.click()
|
||||||
|
time.sleep(10)
|
||||||
|
driver.save_screenshot('./ss/channel_' + str(i) + '.png')
|
||||||
|
time.sleep(waittime)
|
||||||
|
|
||||||
|
driver.quit()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
init_profiles()
|
||||||
|
watching_rch()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -0,0 +1,25 @@
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
selenium:
|
||||||
|
restart: always
|
||||||
|
image: selenium/standalone-chrome:latest
|
||||||
|
container_name: 'selenium'
|
||||||
|
volumes:
|
||||||
|
- /dev/shm:/dev/shm
|
||||||
|
python3:
|
||||||
|
restart: always
|
||||||
|
build: ./python3
|
||||||
|
container_name: 'rpoint-getter'
|
||||||
|
working_dir: '/var/app'
|
||||||
|
tty: true
|
||||||
|
environment:
|
||||||
|
- RAKUTENID=${RAKUTENID}
|
||||||
|
- RAKUTENPW=${RAKUTENPW}
|
||||||
|
volumes:
|
||||||
|
- ./app:/var/app
|
||||||
|
depends_on:
|
||||||
|
- selenium
|
||||||
|
entrypoint:
|
||||||
|
- python3
|
||||||
|
command:
|
||||||
|
- /var/app/main.py
|
|
@ -0,0 +1,5 @@
|
||||||
|
FROM python:3.11
|
||||||
|
|
||||||
|
RUN pip3 install --upgrade pip
|
||||||
|
|
||||||
|
RUN pip3 install selenium
|
Loading…
Reference in New Issue