Python requests library fails to login when hidden elements exists in form

Viewed 41

I am having an issue when trying to log in to a website that has hidden elements inside the form. When hidden elements like <input type="hidden" name="name1" value=""> are exists in the login form, I know those should also pass to the data argument in requests.post(data={}) along with their name and value like below.

import requests

payload = {
    'Email': 'email@gmail.com',
    'Password': 'password',
    # The elements with type="hidden"
    'value_of_name_attribute': 'value of value attribute'}

with requests.Session() as s:
    # Posting login info
    login = s.post('url', data=payload)
    print(login.url)

But there are some websites that they initially don't assign a value to the value attribute. Instead they update the value attribute when submitting the form with Javascript or something. In that case, python requests module fails to login because, there is no way we can update the code after submitting the form.

Is this some kind of trick that websites use to stop this kind of automations. If it is, is there any way to overcome this problem. I know this can be done with selenium but I am expecting a solution with requests library. Any answer would be really appreciated.

0 Answers
Related