I am trying to scrape the current loan note status from the url column of the lending club download data. For example https://lendingclub.com/browse/loanDetail.action?loan_id=104046830 and it requires log in to extract info.
I've followed the steps to create log in session but it seems it cannot perform log in successfully. Result does not contain the right code. Can someone help me to identify the issue?
USERNAME = "username"
PASSWORD = "password"
LOGIN_URL = "https://www.lendingclub.com/auth/login?"
loan_id=96490539
URL = "https://lendingclub.com/browse/loanDetail.action?loan_id=96490539"
def main():
session_requests = requests.session()
# Get login csrf token
result = session_requests.get(LOGIN_URL)
tree = html.fromstring(result.text)
authenticity_token = tree.xpath("//meta[@name='csrf-token']/@content")[0]
# Create payload
payload = {
"login_email": USERNAME,
"login_password": PASSWORD,
"csrf-token": authenticity_token
}
# Perform login
result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
# Scrape url
result = session_requests.get(URL, headers = dict(referer = URL))
return result