Python: Use Request - Instructions
Related Videos: Sockets Tutorial with Python 3 part 1 - sending and receiving data (May 2024).
With a request, you can easily get data from the Internet using Python. We show you exactly how to do this in this Python practical tip.
Install the request library in Python
To create a request, you must first install the request library:
- Look for the "Scripts" subfolder in your Python system folder on your PC.
- Open the Windows command prompt with [Windows] key + [R]> "CMD" and change to the Scripts folder with a special command: "cd C: \ Users \ yourusername \ AppData \ Local \ Programs \ Python \ Python36 \ scripts ". The path may differ slightly.
- Then run the "pip install requests" command (without the quotation marks).
Use request in Python
Next we'll show you how to use a request in Python:
- To do this, add the "import requests" command (without quotation marks) to your code.
- You can now create a request using the command "r = requests.get ('// github.com/timeline.json')".
- With a print command, such as "print r.text", you can have the content output.
More tips about Python in the CHIP guides
Tip: You can find more programming tutorials on our Python programming language topic page. There we will show you, for example, how you can use the string replace function in Python.