A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[python] Gaiaonline Login Script -- Selenium & PhantomJS

2.5k views · started by Kingz V ·
#1
[python] Gaiaonline Login Script -- Selenium & PhantomJS
Just because,

I'll be around to answer questions.

PhantomJS | PhantomJS
Selenium - Web Browser Automation

import json

from selenium import webdriver

class gaiaonline(object):
"""Selenium driver for gaiaonline login"""

def __init__(self):
"""Create driver and store some urls"""
self.driver = webdriver.PhantomJS()
self.home = 'http://gaiaonline.com/'
self.auth = self.home + 'auth'
self.GSI = self.home + 'chat/gsi/?'

def login(self,username, password):
"""Use webdriver to login"""
self.driver.get(self.auth)
self.driver.find_element_by_id("username").send_keys(username)
self.driver.find_element_by_id("password").send_keys(password)
self.driver.find_element_by_id('signInButton').click()
print(self.driver.current_url)

def getSID(self):
"""Grab sid from gsi109"""
url = self.GSI + 'v=json&m=[[109]]'
self.driver.get(url)
return(json.loads(self.driver.find_element_by_tag_name('pre').text)[0][2])

def main():
b = gaiaonline()
b.login('username','password')
print(b.getSID())

if __name__ == '__main__':
main()
[/2][/0][/109]
#2
Might be a dumb question but any particular reason for the chat/gsi endpoint?

edit: nvm, I see you later use that url to access some JSON data, can I ask what exactly the SID is useful for though?
#3
ZeusJuice wrote:
Might be a dumb question but any particular reason for the chat/gsi endpoint?

edit: nvm, I see you later use that url to access some JSON data, can I ask what exactly the SID is useful for though?
it's your authenticated session, so you can use logged-in features
#4
You can use this for Java, correct?
#5
K0balt wrote:
You can use this for Java, correct?


Yes, Selenium is available through a number of different programming languages.
#6
how does this work? <3