Advertisement
daniilak

Untitled

Aug 6th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. from time import sleep
  2. from pickle import dump
  3.  
  4. COOKIES_FILE = 'lib/cookies.pkl'
  5.  
  6.  
  7. from selenium.webdriver.chrome.options import Options
  8. from selenium.webdriver.common.keys import Keys
  9. from seleniumwire import webdriver
  10.  
  11.  
  12. def get_chrome():
  13. print("START get_chrome")
  14. chrome_options = Options()
  15. chrome_options.add_argument('--headless')
  16. chrome_options.add_argument('--no-sandbox')
  17. chrome_options.add_argument('--disable-dev-shm-usage')
  18.  
  19.  
  20. options = {
  21. 'proxy': {
  22. 'http': 'http://login:[email protected]:8000',
  23. 'https': 'https://login:[email protected]:8000',
  24. 'no_proxy': 'localhost,127.0.0.1' # excludes
  25. }
  26. }
  27. d = webdriver.Chrome(executable_path='/usr/bin/chromedriver', seleniumwire_options=options, options=chrome_options)
  28. return d
  29.  
  30. def save_cookie( cookies):
  31. dump(cookies, open(COOKIES_FILE, "wb"))
  32. print("OK save cookies")
  33.  
  34.  
  35. def auth():
  36. print("START auth")
  37. d = get_chrome()
  38. d.get('https://spv.kadastr.ru/api/v1/login')
  39. sleep(3)
  40. # print(d.page_source)
  41. try:
  42. login_field = d.find_element_by_css_selector('input#login')
  43. except:
  44. send_message("SPV скрипт умер, не нашел login поле в госуслугах")
  45. pass_field = d.find_element_by_css_selector('input#password')
  46. # button id="loginByPwdButton" type="button" class="ui-button ui-widget button-big
  47. submit = d.find_element_by_css_selector('.button-big')
  48. login_field.send_keys(LOGIN)
  49. pass_field.send_keys(PASS)
  50. sleep(1)
  51. submit.click()
  52. sleep(3)
  53. d.get('https://spv.kadastr.ru/')
  54. sleep(1)
  55. print("OK auth")
  56. save_cookie(d.get_cookies())
  57. d.quit()
  58.  
  59.  
  60.  
  61. auth()
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement