Python Day 62 – pulling data from websites

Today I started a module on HTTP requests and APIs, which is essentially about pulling data from websites.

I learned:

The library for HTTP requests is ‘requests’, and one of the most useful functions here is the .get request. Once one .get’s a website, one can check if the connection is successful with the .status_code or .ok functions.

Once the connection is established, .content will return the website at bytes and .text will return it as a string.

I’m still confused on:

What’s the significance of returning the data as bytes versus strings? On a similar note, what even is bytes? I don’t know if I’ve conscientiously used that dataset before.

To be honest, I also got a bit lost when the module went over how to format the data so it looks better. Apparently the data comes back as a dictionary, and we can look at the keys and children. The code doesn’t seem very complicated so my brain might just be tired. I shall look into it more tomorrow.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: