LoginSignup
17
23

More than 1 year has passed since last update.

【Python】SBI証券でIPOの申し込みがある場合にLine通知してみた

Last updated at Posted at 2021-09-12

はじめに

みなさんIPOへの申し込みは行っていますか?
私はSBI証券で数年前からポチポチしていたんですが、まぁこの確認が非常に面倒・・・。
通常は以下を定期的に確認する必要があります。

1.WEBブラウザを開く
2.IDとPWを入力する
3.国内株式>IPO・PO をクリック
4.新規上場ブックビルディング/購入意思表示 をクリック
5.[申込]ボタンがあるか確認

これを自動化したい!という記事です。
事前準備や1〜2までの手順は以下の記事にまとめましたので今回は3-5を中心に記載します。

環境

Python3.9
macOS Catalina10.15.7
Chrome 93.0.4577.63

プログラム

前半は前の記事をご確認ください。
後半はLineの通知先だけ変えれば使えると思います。

IPO_moshikomi.py
from selenium import webdriver

ID = open('/Users/Hiroki/Info/ID.txt', 'r', encoding='UTF-8')
IDdata = ID.read()

PW = open('/Users/Hiroki/Info/PW.txt', 'r', encoding='UTF-8')
PWdata = PW.read()

driver = webdriver.Chrome("/Users/Hiroki/Info/chromedriver")
driver.get("https://www.sbisec.co.jp/ETGate")

elem_id_word = driver.find_element_by_name("user_id")
elem_id_word.send_keys(IDdata)

elem_id_word = driver.find_element_by_name("user_password")
elem_id_word.send_keys(PWdata)

elem_id_btn = driver.find_element_by_xpath("/html/body/table/tbody/tr[1]/td[2]/form/div/div/div/p[2]/a/input")
elem_id_btn.click()

######↑ここまでは前回の「【Python】SBI証券に自動ログインしてみた」で解説しています。#####
######↓今回はここから解説します。######

#↓変更不要 申し込みページにジャンプします
driver.get("https://site1.sbisec.co.jp/ETGate/?OutSide=on&_ControlID=WPLETsmR001Control&_DataStoreID=DSWPLETsmR001Control&sw_page=Offer&cat1=home&cat2=none&getFlg=on&sw_param1=21&sw_param2=")

#↓変更不要 申し込みページのソースを読み込みます。
IPO_page_source = driver.page_source

#↓変更不要 申し込みページのソースから[申込]ボタンの画像があるか確認します。
#ここがHirockioポイントですね。
moshikomi = IPO_page_source.find('b_ipo_moshikomi.gif')

#もし[申込]ボタンの画像がない場合は[-1]を返してきますので処理終了。
#もし[申込]ボタンの画像がある場合はLineに通知します。
def if_IPO(moshikomi):

    if moshikomi == -1:
        driver.close()
        driver.quit()
    else:
        addmessage="SBI証券で申し込み可能な" "\r\n""ブックビルがあります。""\r\n""https://www.sbisec.co.jp/ETGate"
        #!!要変更!! line_notify_tokenはご自身で発行して下さい。
        line_notify_token = '*************************************'
        line_notify_api = 'https://notify-api.line.me/api/notify'
        message = addmessage
        payload = {'message':"\r\n"+ message}
        headers = {'Authorization': 'Bearer ' + line_notify_token}  
        line_notify = requests.post(line_notify_api, data=payload, headers=headers)
        driver.close()
        driver.quit()
if_IPO(moshikomi)

最後に

いかがでしたでしょうか。今回は[申込]ボタンの画像に注目してみました。
これを毎日定期的に実行させれば毎日のチェックは不要です。
定期的に実行させるには以下を参考にして下さい。

次は当選した際の動きを書きたいのですが、「当選した時の画像」は当選しないとわからん!
ということで当選したら作りたいと思います・・・。
ご参考になれば幸いです。

17
23
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
17
23