Compare commits

..

No commits in common. "9e8d970dbfb644970f95075e839501c442ca1b11" and "ca54d390a4ecba1d6ef18ba3fe3193062e96cfb6" have entirely different histories.

2 changed files with 11 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
.env .env
__pycache__ __pycache__
nohup.out

View File

@ -5,7 +5,7 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
import time,os,random import time,os
import r_kuji import r_kuji
@ -13,7 +13,6 @@ import r_kuji
profile_dir = "/tmp/profile" profile_dir = "/tmp/profile"
username = os.environ["RAKUTENID"] username = os.environ["RAKUTENID"]
password = os.environ["RAKUTENPW"] password = os.environ["RAKUTENPW"]
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
rch_time = int(os.environ["RCH_WATCH_TIME"]) rch_time = int(os.environ["RCH_WATCH_TIME"])
rch_num = int(os.environ["RCH_WATCH_NUM"]) rch_num = int(os.environ["RCH_WATCH_NUM"])
target_url = "https://channel.rakuten.co.jp/" target_url = "https://channel.rakuten.co.jp/"
@ -31,7 +30,6 @@ def gen_driver():
options = webdriver.ChromeOptions() options = webdriver.ChromeOptions()
options.add_argument("--window-size=1920,1080") options.add_argument("--window-size=1920,1080")
options.add_argument("--user-data-dir=" + profile_dir ) options.add_argument("--user-data-dir=" + profile_dir )
options.add_argument('--user-agent=' + user_agent )
driver = webdriver.Remote( driver = webdriver.Remote(
command_executor="http://selenium:4444/wd/hub", command_executor="http://selenium:4444/wd/hub",
@ -103,38 +101,25 @@ def watching_rch():
element = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body'))) element = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
for i in range(0, rch_num): for i in range(0, rch_num):
# 30秒150秒待機 # 30秒待機
random_seconds = random.randint(30, 150) time.sleep(30)
time.sleep(random_seconds)
print( "Rチャンネル:" + str( i + 1) + "番目のチャンネルの視聴を始めます。視聴時間は" + str(rch_time) + "秒に設定されています。") print( str( i + 1) + "番目のチャンネルの視聴を始めます。視聴時間は" + str(rch_time) + "秒に設定されています。")
driver.save_screenshot('./ss/watching.png')
try: try:
channel_btns = driver.find_elements(By.CSS_SELECTOR, channel_btn_css) channel_btns = driver.find_elements(By.CSS_SELECTOR, channel_btn_css)
channel_btn = channel_btns[i] channel_btn = channel_btns[i]
channel_btn.click() channel_btn.click()
except: except:
print("Rチャンネル:チャンネルが選択できませんでした。") print("チャンネルが選択できませんでした。")
try: driver.save_screenshot('./ss/error.png')
driver.save_screenshot('./ss/error.png')
except:
print("Rチャンネル:スクリーンショットの保存でエラーが発生しました。")
time.sleep(rch_time)
now_time = time.time()
end_time = now_time + rch_time
while time.time() <= end_time:
try:
driver.save_screenshot('./ss/watching.png')
except:
print("Rチャンネル:スクリーンショットの保存でエラーが発生しました。")
time.sleep(30)
try: try:
driver.refresh() driver.refresh()
except: except:
print("Rチャンネル:ページの更新に失敗しました。") print("ページの更新に失敗しました。")
driver.quit() driver.quit()
@ -143,9 +128,7 @@ def main():
watching_rch() watching_rch()
if __name__ == '__main__': if __name__ == '__main__':
# 60-900秒待機 (毎日同時刻にアクセスすることを回避) time.sleep(60) # selniumコンテナの起動を待つ待機
random_seconds = random.randint(60, 900)
time.sleep(random_seconds) # selniumコンテナの起動を待つ待機
main() main()
try: try:
r_kuji.rkuji() r_kuji.rkuji()