Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys
- import os
- import requests
- from bs4 import BeautifulSoup
- import json
- __LOGIN = "LOGIN" ### yours here
- __PASSWORD = "PASSWORD" ### yours here
- __PENENZA_OPTION = 17
- __LOGIN_URL = 'http://my.penenza.ru/main/sso/Login.aspx'
- __POST_LOGIN_URL = 'https://tender.otc.ru/main/sso/Handlers/PostLoginHandler.ashx'
- __HOME_URL = "http://my.penenza.ru/main/tradefinancemvc/Home"
- __LIST_URL = "https://my.penenza.ru/main/tradefinancemvc/FinOffer/List"
- __OFFERS = 'https://my.penenza.ru/main/tradefinancemvc/FinOffer/ExportToExcel?'
- __USER_AGENT = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36"
- def main():
- login_data = {
- 'ctl00$MainContent$txtUserName': __LOGIN,
- 'ctl00$MainContent$txtUserPassword': __PASSWORD,
- 'ctl00$MainContent$ddlPlatforms': __PENENZA_OPTION,
- 'ctl00$MainContent$btnLogin': 'Войти',
- 'ctl00$MainContent$hidSignValue': '',
- 'ctl00$MainContent$hfCertExpDialogResult': ''
- }
- post_login_data = {
- 'IsCrmUser': 'False',
- 'RedirectUrl': 'https%3a%2f%2fmy.penenza.ru%2fmain%2fsso%2fdefault.aspx'
- }
- headers = {'User-Agent': __USER_AGENT }
- with requests.Session() as s:
- s.headers.update(headers)
- page = s.get(__LOGIN_URL, verify=False)
- soup = BeautifulSoup(page.content, "html.parser")
- login_data["__VIEWSTATE"] = soup.select_one("#__VIEWSTATE")["value"]
- login_data["__VIEWSTATEGENERATOR"] = soup.select_one("#__VIEWSTATEGENERATOR")["value"]
- login_data["__EVENTVALIDATION"] = soup.select_one("#__EVENTVALIDATION")["value"]
- first_response = s.post(__LOGIN_URL, data=login_data, verify=False)
- print("---------------------------------------------")
- mini_soup = BeautifulSoup(first_response.content, "html.parser")
- post_login_data["SecurityToken"] = mini_soup.find("input", {"name": "SecurityToken"})["value"]
- second_response = s.post(__POST_LOGIN_URL, data=post_login_data, verify=False)
- print("Status code:", second_response.status_code)
- with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "backoffice.html"), "w") as f:
- f.write(second_response.content.decode('utf-8'))
- print("Well done")
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment