Welcome back, everyone, and my apologies, I got a little ahead of myself in the last lecture mentioning
the challenge, it's in the next lecture.
I wanted to bring this example and present it to you guys so you have more tools able to successfully
complete your scraping projects.
And we had in the last lecture the little snippet mentioning our keys, being able to submit log in
as a password.
And some sites nowadays are password protected or we have to log into them with an account to perform
our scraping.
And I think this is a pretty crucial part.
So let's keep this really straightforward.
Let's set up a example and build a selenium option to log into a site with us.
So for the purpose of this, we're going to be looking to sign in to these super data science dot com
website.
We're going to be able to click.
We want to sign in here.
We don't need to actually click.
We can actually just specify the URL.
So we're going to be looking to sign into the super data science login page with selenium, the purpose
being that we would need to log in to scrape information.
So let's jump into Spider.
I created a new file, Silentium Login Pae.
Let's say our import Siemens will.
We're going to need time to import time and import selenium.
We're going to need the web driver import.
We'll have this wrong.
I want from selenium import web driver to get setup.
All right.
We have them.
As we've done four steps, let's get our Web driver, so driver Egal, Web driver Chrome, and we'll
need to specify the euro, but let's let the page loads of time sleep.
Let's give it five seconds to load the page and we can actually wrap this in a function.
So let's do just fine.
Let's use site login.
And I do not need that many parentheses for this, so we'll delete that and we need to have our specifics
here.
So we're going to specify our URL with the driver.
Don't get.
So driver get.
In Are You, Earl, which will be the super data science dotcoms log, we can add that and this is going
to get our page that we're looking to perform our actions on.
And we can use the fine element by whether it's name, class ID, et cetera, these options.
So I'm going to write this out just so we have a little bit of reproducibility here.
The driver find element by underscore name and we can use name as a first option.
But let's check the page.
So if we go to our inspector, let's grab this.
We need to enter text here using selenium and we can see that the name is specified.
I don't see a class specifically here.
I have an E class, but we have the name.
So that's going to work so we can use fine element by name.
And we have to actually check the name, I think that would be helpful.
The name is email.
All right.
So we have to use that name.
Let's put our parentheses here, its e-mail.
Remember to check the casing as well.
And we would specify our cinches, send keys and let's put in an example so we can see it.
This is my email here.
All right.
Let's also grab this since we don't need to.
Rewrite this code over and over.
I can add that and let's check the password.
The password is a name of password.
And placeholder, OK, so we have input, name, password, type password.
Let's jump back to Spider.
We can keep the name and we could just specify.
Password, let's keep it lowercase, that's fine, and we can have let's have one, two, three, four,
five, six, seven, eight, nine, 10 as our password really, really difficult combination to crack.
Lastly, if we submit these, we have to have a way of clicking this to submit it, as we've done in
the last video, being able to click something, we can grab this.
Let's see.
The button type class is CDs, but OK, but we also see buttons here as well, they do function as buttons
to sign in via LinkedIn or Facebook, and it is a same class with the addition S.A.S..
But LinkedIn.
All right.
I don't want there to be any possible issue.
We can always build other methods.
But for this, I'm going to copy the XPath and we're going to add this in here.
We want to find element.
I should have actually copied this first.
So let's go back and grab that.
Let's grab this.
Let me copy it.
Let's add this fine element by XPath so it becomes pretty straightforward working with this.
Now we want to specify let's grab our copy copy XPath.
A lot of back and forth.
We can add this in.
We have XPath here and we don't want to send the keys since there are no keys to end.
So we would have to click.
Let's remove that.
We can add our parentheses, clean that up and I just want to check this error and my keyboard again
is driving me a little crazy.
I need to have web driver that will solve that again, have those errors.
We're good to go.
So we are moving a little quickly for this.
Just keeping it really straightforward.
Last thing we're going to want to do is initiate this.
So let's do our site log in.
Let's give ourselves some time sleep.
Twenty two hundred nine seconds might be a little too much.
And then we always want to driver quit or close.
We have our driver quit.
And let's run this now to see if the values are keys are sent.
It will click, but it's not going to be successful in the sense of we're not entering our correct email
here so we're not going to log in.
But if you do replaces with your values, my disclaimer here, please do not share your information.
Please keep this sensitive information secret.
So we're using this as an example.
Let's run it and see what happens.
Here we go.
Browsers should come up, should go to the URL.
Give it a few seconds.
Here we go, Page is loading.
There we go.
Keys are sent, we see that the.
Errors thrown because it's not a valid email, but the button would be clicked after we have that,
it would sign in and this is how you would log into a site using selenium.
You would have more specifics built in if you're looking to use beautiful soup as an example of another
language to do some scraping.
But we need to keep these in mind because nowadays a lot of pages require accounts, require setup's.
You have to log in also as a quick note, we actually don't need this.
This was bothering me with the delay when the URL was coming up.
And it's because we specified this.
We don't need to sleep here because we are going to get our login.
So that's fine.
We can remove it to have the page load quicker.
Always remember that it's helpful to have this sleep when the pages loaded so that the content can then
load, so we can just add a comment here to resolve that.
That's no problem.
I hope you guys enjoyed this very straightforward example of submitting keys using selenium.
And now in the next lecture, you're going to find out about the challenge for Silentium.
All right.
I'll see you guys are.