Skip to content

Instantly share code, notes, and snippets.

@tounefr
Created May 4, 2015 09:49
Show Gist options
  • Save tounefr/acf9770af91524127cb1 to your computer and use it in GitHub Desktop.
Save tounefr/acf9770af91524127cb1 to your computer and use it in GitHub Desktop.
import requests
import json
import re
class DofusRequest:
def __init__(self, datas = None):
if datas == None:
datas = {
"username" : "",
"password" : "",
"email" : "",
"captchaChallenge" : "",
"captchaResponse" : "",
"token" : ""
}
self.username = datas["username"]
self.password = datas["password"]
self.email = datas["email"]
self.captchaChallenge = datas["captchaChallenge"]
self.captchaResponse = datas["captchaResponse"]
self.token = datas["token"]
self.sess = requests.Session()
self.sess.verify = False
self.sess.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36"
def testCaptcha(self):
datas = {
"recaptcha_response_field" : self.captchaResponse,
"sAction" : "test",
"sToken" : self.token,
"sLang" : "fr",
"sTestField" : "recaptcha_response_field",
"aFormData[userlogin]" : self.username,
"aFormData[userpassword]" : self.password,
"aFormData[useremail]": self.email,
"aFormData[recaptcha_challenge_field]" : self.captchaChallenge,
"aFormData[recaptcha_response_field]" : self.captchaResponse,
"aFormData[sAction]" : "submit"
}
headers = {
"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With" : "XMLHttpRequest"
}
req = self.sess.post("https://secure.dofus.com/fr/mmorpg/jouer", data=datas, headers=headers)
print(req.text)
return json.loads(req.text)['result']['valid']
def getCaptcha(self):
res = self.getChallengeCaptcha()
self.captchaChallenge = self.reloadCaptcha(res['c'], res['k'])
return self.getImageCaptcha(self.captchaChallenge)
def getChallengeCaptcha(self):
req = self.sess.get("https://www.google.com/recaptcha/api/challenge?k=6LcC2_USAAAAABTeDJnHglk2qKomDK03fCh18fLu")
text = req.text
c = re.search("challenge : '(.*)'", text).group(1)
k = re.search("site : '(.*)'", text).group(1)
return {
"c" : c,
"k" : k
}
def reloadCaptcha(self, m_c, m_k):
req = self.sess.get("https://www.google.com/recaptcha/api/reload?c={c}&k={k}&reason=i&type=image&lang=fr".format(c=m_c, k=m_k))
return re.search("Recaptcha.finish_reload\('(.*)', 'image', null, null\)", req.text).group(1)
def getImageCaptcha(self, c):
req = self.sess.get("https://www.google.com/recaptcha/api/image?c={}".format(c))
print("https://www.google.com/recaptcha/api/image?c={}".format(c))
return req.text
def getCaptcha():
datas = {
"username" : "test",
"password" : "test",
"email" : "test@test.com",
"captchaChallenge" : "",
"captchaResponse" : "",
"token" : "test"
}
dofusRequest = DofusRequest(datas)
dofusRequest.getCaptcha()
return "https://www.google.com/recaptcha/api/image?c=" + dofusRequest.captchaChallenge
urlImage = getCaptcha()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment