Welcome back, everyone.
In this video, this is going to be a short video just to demonstrate request.
This is not only applicable to web scraping, but this is a useful tool across many domains.
And also checking status code errors and status codes will always be helpful whenever you're programming.
All right.
The first thing we're going to want to do is import our library just like any other library import requests
with requests.
We can now set up our connection or target destination to return information.
So let's start with our eagles' requests, douget, and we could pass in the intro here.
You could also pass in information arguments such as user authentication and passwords.
If you're looking for an IP or site connection that you need that information for.
But let's keep it simple.
Let's use Google as an example so we can pass in HTP s Google dot com.
Let's try that.
But as a first check, it's always highly recommended to check your connection.
You're going to check your status code.
Status quo is going to tell you if your connection was successfully run or if there was an error.
And this dash code number will also provide useful context to see if there was an error, what is causing
error, what is reason to help you debug.
So let's try the R, so try to print our status code and let's run it.
And there we have it, 200 is a successful status quo.
So we have sent our connection and it's been a success, but there's even more that we can do.
And these are just a few examples.
Let's try to print our headers.
We want to check the content type of our headers so we can establish the content type.
Lets take the content type.
Let's check the encoding of the page.
We can do print are encoding.
We want to check that just in case we're working with any specific encoding the page.
And you know what?
Since we're going with our request get and we're retrieving the connection from the URL, let's try
to print the text of the e-mail document so we could do a print text.
It's a pretty straightforward, pretty simple method.
Let's run these.
And there you have it, we have returned successfully the information that scroll up because we want
to check those other print statements as well.
We have our 200 statis code.
We have the encoding, we have our content type and we have the text from our requests.
In addition, I'll provide the following links as a resource.
If you guys are ever looking to debug or check status codes, these are very useful.
If we visit them, you can check the MDN Web docs for ranges of status codes, which is really helpful
when debugging again, cannot say enough about this.
You can see our successful responses are going to be between 200 to 99.
We have the ranges of response status quotes we can see redirects kliner server errors.
So this is just going to be useful.
So you have 300 or pick a number three or four.
We want to check what that air is going to be.
You can go through and check the status codes for the errors that you received.
So if we had three or four, this would be a not modified.
And this is really useful for debugging.
You also have HIV status dogs.
I mean, why not?
If you're going to check status codes, these can be really helpful as well.
And you have an HTTP status dog along with the code.
So I will include the links for these.
If you guys would like to access them and take a look at more information, let's jump back in to Spider.
We can see and these are just a few examples of requests.
We're pulling information to help us get started.
With our connection, our request to get to are you, Earl, that we're looking to crawl really, really
powerful library cannot say enough about it.
We're going to wrap it up here in the next lecture.
We're going to get started with beautiful soup.
And I will see you there.