🛜 Access internet using Python


Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python.

Every time you open a website, your browser (let's say Chrome) does the work for you.

It sends a request. The server replies with data. Basic internet workflow.

With Python's requests library, same can be done - through code.

So fetch data, send information (fill a form) or check if the website is live - only in a few lines.

Let's see how!

📞 get to ask for data

200 means OK. Request worked and server returned the data.

In:
import requests
r = requests.get("https://httpbin.org/get")
print(r.status_code)
Out: 200

📩 See reply

Its fine if you don't understand what the reply means for now

In:
r = requests.get("https://httpbin.org/get")
print(r.text[:80])

👤 See only specific data

If you want to see data for Alex aged 25, pass the parameters to get custom url.

In:
params = {"name": "Alex", "age": 25}
r = requests.get("https://httpbin.org/get", params=params)
print(r.url)
Out: https://httpbin.org/get?name=Alex&age=25

Open this url to see what you got

⏱️ Timeout to protect yourself - Quit if server does not reply

In:
try:
    r = requests.get("https://httpbin.org/delay/5", timeout=2)
except requests.exceptions.Timeout:
    print("Request timed out")

📬 Send information ➜ post request

In:
payload = {"task": "Finish report", "done": False}
r = requests.post("https://httpbin.org/post", data=payload)
print(r.text)

🔑 Pass username and password

In:
r = requests.get("https://httpbin.org/basic-auth/alex/secret",
            auth=("alex", "secret"))
print(r.status_code)
Out: 200

It worked!!


💡 Quick Excel Tip

Ctrl + T ➜ Turn data into table instantly


⭐📣 That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. You have a spreadsheet with 500 numbers. Your boss asks: "What do you see?" Most will freeze, scroll, guess. Not you! 3 Python functions to turn raw numbers into answers. No calculator, excel sheets. Just code. Statistics isn't boring math. It's how you make decisions with data. Using just the statistics module we find "center" of any dataset. Any data analyst must know the basics‼️ 🎯 Compute simple...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Last week we introduced numpy. Created bunch of arrays, sliced them and did some math with them. To prepare data for machine learning or any analysis, we need to learn to control their shape. Today - Reshape flat lists into grids. Flatten 2D tables back to 1D arrays. Create arrays filled with zeros, ones, or random numbers. ⏪ Recap: See dimensions first In: import numpy as np sales = np.array([120, 340,...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. TGIF! Everyone is talking about AI. Most people take courses. You're going to build it instead. Let's create a simple sentiment analyzer that reads customer reviews and classifies them as positive or negative. No machine learning libraries—just Python. 🎯 Define list of positive and negative words In: positive_words = ["good", "great", "excellent", "amazing", "love", "best"] negative_words = ["bad",...