Before I Start The Explanation, This Is A Recording Of What The Code Does.
π
In The 1st Line, We Are Importing Selenium.
@SeleniumHQ Is A Tool Which Helps Us Automate Tasks In Web Browsers. We Can Automatically Click Buttons, Fill Text Fields, Get The Data From Web Page And Many Other Things, All By Code.
π
In The 2nd Line We Are Giving The Path To Our Webdriver, In This Case The Chrome Webdriver (We Can Use Other Browsers Too).
In The 3rd Line, We Are Just Telling The Browser To Open A Website, Which In This Case Is facebook.com
In The 4th And 5th Line, We Are Just Saving Our Username And Password In Variables, These Values Would Be Put On The Text Fields On The Facebook Login Page
π
After The FB Login Page Is Opened
In The 6th And 7th Lines, We Are Finding The Text Fields On The Page With The 'id' Their HTML Tags Are Given
Now How Did I Get Those?
Just Right Click On The Text Field And Click On Inspect, A Window With A Lot Of HTML Code Will Open Up
π
There Will Be Some Highlighted Code, In This Case It Will Be An Input Tag Which Several Attributes, The Attribute We Are Interested In Is 'id'.
So Go Ahead And Copy The Value Of The 'id' Onto Your Code.
The ID Helps Selenium Recognize Which Text Field We Are Looking For
π
Now After We Have Found Our Text Fields, We Want To Fill In Our Details There.
In The 8th And 9th Lines, Tell Selenium To Fill In Our Email And Password In Our Text field.
π
In The 10th Line, We Our Finding Our Login Button On The Page In The Same Way We Did For Our Text Fields.
And All The 11th Line Does Is To Tell Selenium To Click On That Login Button.
And There You Go, Your Logged In Account Will Open Up In Your Browser
π
THATS IT!!
JUST 11 LINES OF CODE!
And You Build A Python Bot Which Automatically Logs In To Facebook For You!
This Is How Easy It Is
π
If You Learnt Something New Today And Liked It,
Then Please Like And RT This Thread So More People See It!!
"Colab allows anybody to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis and education."
π
In Simple Words,
Google Colab Let's You Write Python Code In the Browser And Executes It On Their Cloud CPU, GPU or TPU.
If You Want To Host Your Bot Or Your Dynamic Website Or Any Program, @heroku Is One Of The Best Places To Start, Go Ahead Create An Account And Upload Your Project And Get It Up And Running In Less Than 10 mins. Check Them Out Here -