Submit form in python

Asked

Viewed 690 times

1

I’m trying to submit a form on the website https://www.loskatchorros.com.br/ucp/login.php ,but I’ve searched several ways here on stackoverflow how to submit a form, and found no way to solve this problem.

This is an example of code I picked up here on the forum and it didn’t work.

import requests
headers = {'User-Agent': 'Mozilla/5.0'}
payload = {'login':'*******','senha':'******'}

session = requests.Session()
r = session.post('https://www.loskatchorros.com.br/ucp/login.php',headers=headers,data=payload)

When placing the line:

print (r.text)

The program returns the same source code as the page https://www.loskatchorros.com.br/ucp/login.php, This gives to understand that the form was not successfully submitted, and I wanted to know what I am doing wrong.

If you need real login and password ask me to send it without any problem

2 answers

1


import requests

account = {'login': '[email protected]', 'senha': 'muze123'}
abs_domain = 'https://www.loskatchorros.com.br/' #1
form = 'ucp/global/verifica_login.php' #2
absolute_form_URL = abs_domain + form 

requests_session = requests.Session() #3
r = requests_session.post(url=absolute_form_URL, data=account) #4

text = r.text[-79:] if r.status_code == 200 else None #5
print('Status code [%s].' % r.status_code, text, sep='\n')
  • #1 Absolute domain
  • #2 Path to authentication form
  • #3 "Instance by session"
  • #4 Makes the POST method with the Session object
  • #5 Get a slice of the received text if authentication is successful

>>> Status code [200].
>>> Usuário ou senha incorretos, verifique e tente novamente!</div></body> </html>

  • By providing your credentials here, you are very likely to delete your account. Try using Selenium in these redirect cases. It seems to me he’s trying to open a window with cloudfire.

0

You have to send the post with the data to the destination page of the form, not to the page that generates the form in HTML.

The URL for this page is in the "action" field of the tag form. In that case, global/verifica_login.php (and not login.php).

In modern web frameworks in general the URL that generates the html of a form and the one that processes the form is the same - and this facilitates the creation of the data validation interface. But the author of a site can put the addresses you want, and if it’s a handmade system, without taking advantage of code from a framework, it’s easier to have separate pages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.