From the course: Python: XML, JSON, and the Web
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Retrieving data - Python Tutorial
From the course: Python: XML, JSON, and the Web
Retrieving data
- [Instructor] Now that we've seen an overview of the various urllib modules, let's dive in and try retrieving some data from a server. So here in VS Code, I'm going to open up urllib_start.py in my urllib folder and I'm going to begin by importing the urllib module, specifically the request class, all right. And in the main function, I'll add some code to access a test URL. And in this case, I'm going to use the URL at httpbin.org that returns some test XML data. So I've already defined a variable for the URL so I need to call the URL open function to get the data so I'll write result equals and there'll be the urllib.request.urlopen and I'll use the url. And for the moment, let's just print out the returned HTTP response code to make sure that the request worked. So I'll print Result code and I'll use the string format function for this and that's going to be result.status, all right. So let's run what we have so far. Now I'm going to run this program within VS Code 'cause I have it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.