Nov-29-2017, 05:15 PM
I'm developing a Web Crawler in Python 3.4 to Scrap some info from a Call Reporter platform developed in ASP.NET. I already did all the code to scrap the content I want and the only thing is left to finish my script is the login.
What i need to login a system built on ASP.NET by a Python Web Crawler?
The code below is the login part of my script:
import requests from lxml import html USERNAME = "<USERNAME>" PASSWORD = "<PASSWORD>" LOGIN_URL = "<LOGIN_URL" URL = "<URL>" def main(): session_requests = requests.session() # Get login hash - VIEWSTATE result = session_requests.get(LOGIN_URL) tree = html.fromstring(result.text) HASH = list(set(tree.xpath("//input[@name='__VIEWSTATE']/@value")))[0] # Create payload payload = { "LoginViewControl$userLogonControl$UserName": USERNAME, "LoginViewControl$userLogonControl$Password": PASSWORD, "LoginViewControl$userLogonControl$DropDownLanguage": "English-US", "LoginViewControl$userLogonControl$PasswordHash": HASH } # Perform login session_requests.get(LOGIN_URL, data=payload, headers=dict(referer=LOGIN_URL)) """ The script continues """