Answer the question
In order to leave comments, you need to log in
Python requests how to form a second request?
Good afternoon!
It is necessary to automate the work on the site.
I don’t give a link, because The site can only be accessed from the corporate network.
You need to get new users.
Fill in the user data in the form using the required link, click the add button.
After that, a table with the entered data is loaded, which must be confirmed with the "Confirm" button.
Next, we get a table with credentials and a password that needs to be parsed.
1st request: authorization + entering parameters
import requests
login = 'login'
password = 'pswd'
base_url = 'http://test.ru/?action=user_edit'
def get_html(url):
session = requests.Session()
res = session.get(url)
cookies = dict(res.cookies)
#параметры для первого запроса с авторизацией и вводом данных
params1 = {
'login':login,
'pass':password,
'sp_code': '67',
'contract_number': '111',
'email': '[email protected]',
'phone': '111111111',
'phone_mobile': '11111111',
'apply': 'Добавить'
}
#параметры для второго запроса, подтвердить данные
params2 = {
'confirm': 'Подтвердить'
}
r = session.post(url, data = params1, cookies = cookies) #1й запрос
return r.text
def main():
page = get_html(base_url)
print(page)
if __name__ == '__main__':
main()
Answer the question
In order to leave comments, you need to log in
why don't you want to put params1/parpams2 in list?
and then call it in a loop through this list: first element, second element
for i in params_list:
... для i[0]
... для i[1]
for paramkey in param_dict.keys():
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question