I tried to automate a certain task in a browser game called "My Koshien" using Python. I don't use Python at all, so it's a beginner level code. Please note.
It is a high school baseball simulation game. Although it is a baseball game, the actual game is played by the CPU, and the player is mainly instructed as a manager. Points are required for this instruction, and among some points there is ** Passion PT **, which can be increased by greeting other schools (other players).
This time, I created a script to automate this greeting, so I would like to introduce it.
The following Python libraries are used for automation.
To use Selenium, you need to download the Chrome Driver separately.
orekou.py
import random, urllib, requests
from bs4 import BeautifulSoup
def getSchoolURL():
#Randomly select a district
area_num = random.randint(1, 49)
#Get school link information in a list
html = urllib.request.urlopen("http://orekou.net/profile/school_list/" + str(area_num)).read()
soup = BeautifulSoup(html)
link_elem = soup.select(".sub_content a")
#Randomly select one from the schools on the list
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
#Load an existing profile and generate a Chrome driver
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:\\Users\\<username>\\AppData\\Local\\Google\\Chrome\\User Data")
chrome = webdriver.Chrome("./chromedriver_win32/chromedriver.exe", options=options)
#Open Chrome browser
chrome.execute_script("window.open('', '_brank');")
#Say hello to 100 randomly selected schools
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()
Since you need to log in to the browser game, we have included a process to get an existing profile.
The
It takes about 3 seconds to say hello to one school, so it takes ** about 5 minutes ** to finish 100 schools. Much faster than doing it manually!
If you apply for a practice match at another school, you can earn points more efficiently than greeting. .. .. I want to earn more points! !! If you are a crazy person, please try using the script.
Recommended Posts