Guest User

Untitled

a guest
Sep 16th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import urllib.request
  2. import urllib.parse
  3. import http.cookiejar
  4.  
  5. import re
  6.  
  7.  
  8. def main():
  9.     get_tukan_request = urllib.request.Request(url="https://www.okoun.cz")
  10.  
  11.     with urllib.request.urlopen(get_tukan_request) as response:
  12.         text = response.read().decode("utf-8")
  13.  
  14.     match = re.search(r'<input type="hidden" name="tukan" value="(.+)">', text)
  15.     if match is not None:
  16.         tukan = match[1]
  17.  
  18.         login_data = urllib.parse.urlencode({
  19.             "login": "username",
  20.             "password": "secret",
  21.             "doLogin": "1",
  22.             "topicId": "1",
  23.             "tukan": tukan
  24.         })
  25.         login_data = login_data.encode('ascii')
  26.  
  27.         cookie_jar = http.cookiejar.CookieJar()
  28.         opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
  29.         with opener.open(fullurl="https://www.okoun.cz", data=login_data) as response:
  30.             print(response.status)
  31.             print(cookie_jar)
  32.  
  33.         with opener.open(fullurl="https://www.okoun.cz/favourites.jsp?new=1") as authenticated_get_response:
  34.             text = authenticated_get_response.read().decode("utf-8")
  35.             print(text)
  36.             assert("Jakožto nepřihlášený uživatel nemáte přístup k seznamu oblíbených klubů" not in text)
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     main()
  41.  
Add Comment
Please, Sign In to add comment