I have a webpage https://freddiemac.embs.com/FLoan/secure/login.php
where i need to provide the login information and then after successful login, i will land on a different webpage https://freddiemac.embs.com/FLoan/Data/download.php
from where i need to tick the terms & condition tickbox and click on continue and the page refreshes to display a bunch of zip
files that i need to download.
I am using below code for logging to website:
import urllib
import urllib.request
import http.cookiejar
payload = {'username': 'username', 'password': 'password','submit': 'Submit Credentials'}
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
login_data = urllib.parse.urlencode(payload)
binary_data = login_data.encode('utf8')
opener.open('https://freddiemac.embs.com/FLoan/secure/login.php', binary_data)
resp = opener.open('https://freddiemac.embs.com/FLoan/Data/download.php')
print(resp.read())
I am getting below result, which i feel is the content of the https://freddiemac.embs.com/FLoan/secure/login.php
page only.
b'\n<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<title>Freddie Mac Loan
History</title>\r\n<link rel=\'stylesheet\' type=\'text/css\'
href=\'/FLoan/app_corp.css\'>\r\n<link rel=\'stylesheet\' type=\'text/css\'
href=\'/FLoan/empty.css\'>\r\n<link rel=\'stylesheet\' type=\'text/css\'
href=\'/FLoan/empty2.css\'>\r\n</head>\r\n<body>\r\n<H2>Please log
in</H2>\n\t<form name=\'loginform\' action=\'auth.php\' method=\'post\'
class=\'form\'>\n\t<div class=\'row\'><div class=\'small-5 column\'
>\n\t<label for="username" >Enter email address:</label>\n\t<input
name=\'username\' type=\'email\' placeholder=\'name@company.com\'>
</p>\n\t</div></div>\n\t<div class=\'row\'><div class=\'small-5 column\'
>\n\t<label for="password" >Enter password:</label>\n\t<input
name=\'password\' type=\'password\' autocomplete=\'off\'>\n\t</div>
</div>\n\t<div class=\'row\'><div class=\'small-5 column\' >\n\t<input
type=\'submit\' value=\'Submit Credentials\' class=\'fmSubmit\'>\n\t</div>
</div>\n\t</form>\n\t</p>\n\n</div></div></body></html>\n'
I followed the steps as given under the thread How to use Python to login to a webpage and retrieve cookies for later usage?
Appreciate your help!!