{{tag>projects cloud club computing virtualization machines VMs AWS Azure GCP}} [[python_club|About the Club]]\\ ==== Python Club Topics - Exercise: Get webpage status ==== ==== Exercise: Get webpage ==== - Output: Display the number of each vowel in a given string. - What you learn from the example: - Manipulate strings - Use the built-in count function - use a dictionary ==== Solution ==== # Import the 'requests' module for making HTTP requests. import requests # Define the URL of the web page to be accessed. url = 'http://www.example.com/' # Define headers to mimic a user agent (browser) for the request. headers = {'User-Agent': 'Mozilla/5.0 (Macintosh) Gecko/20100101 Firefox/38.0'} # Use the 'get' method from the 'requests' module to make an HTTP request to the specified URL with headers. request = requests.get(url, headers=headers) # Print the status of the web page request. print('Web page status: ', request) # Print HTML code of the web page if the request was successful (status code 200). print('\nHTML code of the above web page:') if request.ok: print(request.text)