Compare commits
4 Commits
68903176b1
...
19ccd06623
Author | SHA1 | Date |
---|---|---|
|
19ccd06623 | |
|
09657aad4f | |
|
0653cf1711 | |
|
0e8bc1852f |
|
@ -1 +1,2 @@
|
|||
.env
|
||||
.env
|
||||
__pycache__
|
|
@ -7,6 +7,8 @@ from selenium.webdriver.support import expected_conditions as EC
|
|||
from selenium.webdriver.common.keys import Keys
|
||||
import time,os
|
||||
|
||||
import r_kuji
|
||||
|
||||
# 変数初期化 ********************************************************************
|
||||
profile_dir = "/tmp/profile"
|
||||
username = os.environ["RAKUTENID"]
|
||||
|
@ -122,4 +124,8 @@ def main():
|
|||
|
||||
if __name__ == '__main__':
|
||||
time.sleep(60) # selniumコンテナの起動を待つ待機
|
||||
main()
|
||||
main()
|
||||
try:
|
||||
r_kuji.rkuji()
|
||||
except:
|
||||
print("rkuji 失敗")
|
|
@ -0,0 +1,61 @@
|
|||
|
||||
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
|
||||
|
||||
rkuji_list_url = "https://rakucoin.appspot.com/rakuten/kuji/"
|
||||
rkuji_list_xpath = "//table/tbody/tr/td/a"
|
||||
|
||||
class class_rkuji:
|
||||
def __init__(self, profile_dir="/tmp/profile"):
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--user-data-dir=" + profile_dir )
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor="http://selenium:4444/wd/hub",
|
||||
options=options
|
||||
)
|
||||
|
||||
def get_rkuji_urls(self, url, xpath):
|
||||
self.driver.get(url)
|
||||
self.urls = self.driver.find_elements(By.XPATH, xpath)
|
||||
self.url_txts = [url.get_attribute("href") for url in self.urls ]
|
||||
|
||||
def challenge_rkuji(self):
|
||||
for u in self.url_txts:
|
||||
if 'redirect' in u:
|
||||
print(f'ラッキーくじ:「{u}」はスキップ。(理由:redirect)')
|
||||
continue
|
||||
try:
|
||||
self.driver.get(u)
|
||||
kuji_title = self.driver.title
|
||||
except:
|
||||
print(f'ラッキーくじ:「{u}」はスキップ。(理由:アクセス失敗)')
|
||||
continue
|
||||
|
||||
if(len(self.driver.find_elements(By.ID, "entry"))>0):
|
||||
print(f'ラッキーくじ:くじを引きます。({kuji_title})')
|
||||
time.sleep(5)
|
||||
try:
|
||||
start_button = self.driver.find_element(By.ID, "entry")
|
||||
start_button.click()
|
||||
WebDriverWait(self.driver,60).until(EC.url_changes(u))
|
||||
print(f'ラッキーくじ:くじを引きました。({kuji_title})')
|
||||
self.driver.save_screenshot('./ss/r_kuji.png')
|
||||
time.sleep(5)
|
||||
except:
|
||||
(f'ラッキーくじ:「{kuji_title}」はスキップ。(理由:くじ引き失敗)')
|
||||
else:
|
||||
print(f'ラッキーくじ:「{kuji_title}」はスキップ。(理由:くじ引き不能)')
|
||||
|
||||
def close(self):
|
||||
self.driver.quit()
|
||||
|
||||
def rkuji():
|
||||
driver = class_rkuji()
|
||||
driver.get_rkuji_urls(rkuji_list_url, rkuji_list_xpath)
|
||||
driver.challenge_rkuji()
|
||||
driver.close()
|
|
@ -6,6 +6,8 @@ services:
|
|||
container_name: 'selenium'
|
||||
volumes:
|
||||
- /dev/shm:/dev/shm
|
||||
logging:
|
||||
driver: none
|
||||
python3:
|
||||
build: ./python3
|
||||
container_name: 'rpoint-getter'
|
||||
|
|
Loading…
Reference in New Issue