Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import urllib.parse
- import http.cookiejar
- import re
- def main():
- get_tukan_request = urllib.request.Request(url="https://www.okoun.cz")
- with urllib.request.urlopen(get_tukan_request) as response:
- text = response.read().decode("utf-8")
- match = re.search(r'<input type="hidden" name="tukan" value="(.+)">', text)
- if match is not None:
- tukan = match[1]
- login_data = urllib.parse.urlencode({
- "login": "username",
- "password": "secret",
- "doLogin": "1",
- "topicId": "1",
- "tukan": tukan
- })
- login_data = login_data.encode('ascii')
- cookie_jar = http.cookiejar.CookieJar()
- opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
- with opener.open(fullurl="https://www.okoun.cz", data=login_data) as response:
- print(response.status)
- print(cookie_jar)
- with opener.open(fullurl="https://www.okoun.cz/favourites.jsp?new=1") as authenticated_get_response:
- text = authenticated_get_response.read().decode("utf-8")
- print(text)
- assert("Jakožto nepřihlášený uživatel nemáte přístup k seznamu oblíbených klubů" not in text)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment