Skip to content

Instantly share code, notes, and snippets.

@kotx
Last active June 14, 2018 01:28
Show Gist options
  • Save kotx/7831331974405c0d9e2b3d351c51d33f to your computer and use it in GitHub Desktop.
Save kotx/7831331974405c0d9e2b3d351c51d33f to your computer and use it in GitHub Desktop.
NSelenium - An automated script for nationstates challenges

NSelenium is a selenium script in python for nationstates challenges. It automates the challenges, provided that you login first.

This was made in an hour or two, so you'll most likely experience bugs. If you find any, feel free to make a comment!

This script supports matchmaker, random world and region. Simply change

btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "matchmaker")))

to

btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "your choice (matchmaker, random, or randomr)")))

Note: I do not encourage the use of this script, as it is against the Scripting Rules.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://www.nationstates.net/page=challenge")
start = False
go = False
r = 0
while True:
try:
if not start:
btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "matchmaker")))
btn.click()
start = True
if not go:
gobtn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "go")))
gobtn.click()
go = True
name = "round-" + str(r + 1)
elem = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, name)))
elem.click()
except KeyboardInterrupt:
print("KeyboardInterrupt, closing window...")
driver.close()
except TimeoutException:
d = 0
if driver.current_url != "https://www.nationstates.net/page=challenge":
driver.get("https://www.nationstates.net/page=challenge")
continue
try:
reroll = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Reroll")))
reroll.click()
except:
d = 1
if d:
continue
go = False
r = 0
continue
r += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment