0
I want to create a python BOT to send login POST requests, and then send another request to create character, but when I run the code it does not create any character, someone can help me ?
import requests
import random
def gera_char(tamanho):
caracters = 'abcdefghijlmnopqrstuwvxz'
senha = ''
for char in xrange(tamanho):
senha += random.choice(caracters)
return senha
login = raw_input("login: ")
password = raw_input("password: ")
#gerador de nome para o char
charname = gera_char(8)
#urls
url_login = 'http://nto-hard.com/?subtopic=accountmanagement'
url_make = 'http://nto-hard.com/?subtopic=accountmanagement&action=createcharacter'
#dados
dados_make = {
"newcharname": charname,
"newcharsex": "1",
"newcharvocation": "29",
"savecharacter": "1",
"Submit.x": "52",
"Submit.y": "12",
"world": "0"
}
dados_login = {
"account_login": login,
"login.x": "49",
"login.y": "0",
"page": "overview",
"password_login": password
}
requests.post(url_login, data=dados_login)
requests.post(url_make, data=dados_make)
You don’t need to use the reply in the login request to be able to do the second one? As the second request will be that you have already logged in?
– Woss
I can’t test it, but the comment above is more or less in the way; you need to save the session information (cookies) from the login. To do this, create a request.Session instance and call its post functions instead of how you’re doing it. (
s = requests.Session()
,s.post(...)
.– Pedro von Hertwig Batista
I was thinking exactly about cookies, but I don’t know how to use the requests very well... I will search about
– Courin da mata
Unless you really want to learn how to use requests and how things work I would advise you to use the Selenium. Otherwise it is still possible to use the extension for Firefox and based on the actions you perform in the browser export the equivalent code in Python.
– Luiz Guilherme Ribeiro