From the course: Python Standard Library Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Retrieving internet data - Python Tutorial
From the course: Python Standard Library Essential Training
Retrieving internet data
- [Instructor] Now that we've seen how to deconstruct and parse URLs, let's look at how to use Python to access data over the Internet. The standard library module used to do this is the urllib.request module. I've pulled up the docs for this module at this link where you can learn more about it. But, for now, let's just over to the code and try it out. Right, so here in my editor, I'm going to open up retrieve_start and I've already imported the urllib.request module and I have a string variable that refers to a URL, and this URL just uses the httpbin.org testing service and will respond with some sample XML data. So, to access the URL, we first need to call the urlopen function on the request class. So, let's do that. So, I'll get a response back and I'm going to use URL lib's request and I'm going to call urlopen on my sample URL. So, this will open the URL and create a response object. So, before we can read data from the URL, we should first check the status code that was…
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.