How to login to websites automatically
Published in · 5 min read · Jul 18, 2022
--
Automating the login process can be helpful in accessing the information on websites. For example, you may want to update your account settings automatically, or you may want to scrape some web pages and extract some data, but you are first required to log in with your credentials.
In this article, I will present a Python program that will access the GitHub website, enter login credentials, and sign into the website.
Disclaimer: This article is only for educational purposes. We do not encourage anyone to scrape websites, especially those web properties that may have terms and conditions against such actions.
Review the Web Page’s HTML Structure
First, we need to understand the structure and contents of the HTML tags within the web page. For this project, we will be using the GitHub login webpage (shown below). You can access this webpage by selecting this link.
We can sign into this website by finding the input fields, entering the required data, and clicking the Sign in button. To find the HTML tags for the input fields on this web page, right, click anywhere on the web page, select inspect from the drop-down list, click the arrow icon in the upper left-hand side of the screen with the HTML and then click the Username or email address input field. This will result in the following screen being displayed.
We can see that the Username or email address field has an id = “login_field” and the password field has an id = “password”. If you scroll down a little you will see that the Sign in button has a name = “commit”.
So if you want to enter a username, you would follow these steps.
1. Create a variable containing your username or email address.
2. Find the username field where id = “login_field”.