![]() ![]() Here is a fragment of the HTML of the page printed by our program… For this reason you also need to remember to decode the bytes object from the read() method to string using the decode() method. ![]() The urlopen function returns a bytes object because there is no way for urlopen to know the encoding of the stream it receives from the HTTP server. Use the urlopen function of the urllib.request module to get the HTML of the Youtube search page.įor HTTP and HTTPS URLs, the urlopen function returns a object whose body can be read using the read() method.Python programs can access the code in another module using the import statement, so let’s: I will use urllib.request to get the HTML for the search results page on Youtube and print its HTML. The one we are interested in is urllib.request that can be used to open and read URLs. The main package used in Python to work with URLs is urllib and it includes several modules. Let’s start creating a simple Python program that does this specific search and returns the HTML from Youtube. So, the only part of the URL that changes is the search term. If I search for “Mozart” directly in Youtube I get redirected to the following URL: First of all, in order to be able to search for videos using a program we need to understand the URL structure used by Youtube when we search for a video. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |