You can download this code by clicking the button below.
This code is now available for download.
This function is used to fetch content from a specified URL. If the request is successful, it returns the content; otherwise, it returns a failure message.
Technology Stack : Requests library
Code Type : HTTP request function
Code Difficulty : Intermediate
import requests
import random
def fetch_random_url(url):
response = requests.get(url)
if response.status_code == 200:
return response.text
else:
return "Failed to fetch the URL"