To open a web page using Python and retrieve its content, you can use the requests
library. Here's an example of how you can do it:
First, you need to install the requests
library if you don't already have it. You can use the following command in your terminal or command prompt to install it:
pip install requests
Once you have requests
installed, you can use the following Python code to open a web page and retrieve its content:
import requests
# Specify the URL of the web page you want to open
url = "https://example.com"
# Send a GET request to the URL and store the response
response = requests.get(url)
# Retrieve the content of the web page
content = response.text
# Print the content
print(content)
Make sure to replace "https://example.com"
with the actual URL of the web page you want to open.
The requests.get(url)
function sends a GET request to the specified URL and returns a Response
object. The response.text
attribute retrieves the content of the web page in a string format.
You can then manipulate or process the content
variable as per your requirements.