LoginSignup
3
1

More than 3 years have passed since last update.

俺の甲子園で挨拶しまくるスクリプトを作った

Last updated at Posted at 2020-02-02

「俺の甲子園」というブラウザゲーム内のとある作業を、Pythonを使って自動化してみました。
Pythonは普段全然使わないので、初心者レベルのコードです。ご了承ください。

俺の甲子園とは

高校野球シミュレーションゲームです。
野球ゲームですが、実際の試合はCPUによって行われていて、プレーヤーは監督となって指導することがメインになります。
この指導のためにはポイントが必要で、いくつかあるポイントの中に情熱PTというものがあり、他校(他のプレーヤー)に挨拶することで増やすことができます。

今回、この挨拶を自動化するスクリプトを作成しましたので、紹介したいと思います。

ライブラリ

自動化にあたって、Pythonの以下のライブラリを使用しています。
- random
- urllib
- requests
- Beautiful Soup
- Selenium

Selenium使用のため、別途Chrome Driverをダウンロードする必要があります。

スクリプト

orekou.py
import random, urllib, requests
from bs4 import BeautifulSoup

def getSchoolURL():
    #地区をランダムに選択
    area_num = random.randint(1, 49)

    #学校のリンク情報をリストで取得
    html = urllib.request.urlopen("http://orekou.net/profile/school_list/" + str(area_num)).read()
    soup = BeautifulSoup(html)
    link_elem = soup.select(".sub_content a")

    #リストにある学校の中からランダムで1つ選択
    school_num = random.randint(1, len(link_elem))
    school_url = "http://orekou.net" + link_elem[school_num-1].get("href")

    return school_url
greet.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import orekou

#既存のプロファイルを読み込んでChromeドライバを生成
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:\\Users\\<ユーザー名>\\AppData\\Local\\Google\\Chrome\\User Data")
chrome = webdriver.Chrome("./chromedriver_win32/chromedriver.exe", options=options)

#Chromeブラウザを開く
chrome.execute_script("window.open('', '_brank');")

#ランダムに選んだ100校に挨拶する
for index in range(100):
    chrome.get(orekou.getSchoolURL())
    chrome.switch_to.window(chrome.window_handles[0])
    chrome.execute_script("document.getElementsByTagName('input')[2].click();")

chrome.quit()

ブラウザゲームのログインが必要なので、既存のプロファイルを取得する処理を入れています。
上記の<ユーザー名>の部分はユーザー毎に異なるので、各自で変更してください。
挨拶によるポイント獲得は100回までなので、ループも同じ回数しています。

結果

1校へ挨拶するのに約3秒かかりますので、100校終えるのに約5分です。
手作業でするより遥かに速い!

実は...

他校に練習試合を申し込むと、挨拶するより効率的にポイントを稼げます。。。
もっとポイントを稼ぎたいんだ!!っていうガチ勢の方、是非スクリプトを活用してみてください。

3
1
1

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