Use the text attribute of the object r to return the HTML of the webpage as a string; store the result in a variable text.
时间: 2024-04-20 18:24:36 浏览: 90
To return the HTML of a webpage as a string using the "text" attribute of the "r" object, you can follow these steps:
```python
import requests
# Make a GET request to the webpage
response = requests.get("https://www.example.com")
# Access the "text" attribute of the response object to get the HTML content
text = response.text
# Print or use the variable "text" as needed
print(text)
```
In this example, we are using the requests library in Python to make a GET request to the webpage. The response object "response" contains various attributes like "text", "status_code", etc. Accessing the "text" attribute will give you the HTML content of the webpage as a string, which can be stored in the variable "text".
阅读全文